optimized
This commit is contained in:
@@ -316,7 +316,6 @@ public class FlowerApiController : BaseController
|
||||
var flower = database.Flowers.SingleOrDefault(f => f.Id == update.Id && f.OwnerId == user.Id);
|
||||
if (flower == null)
|
||||
{
|
||||
SaveDatabase();
|
||||
return NotFound(update.Id);
|
||||
}
|
||||
flower.CategoryId = update.CategoryId;
|
||||
@@ -378,7 +377,6 @@ public class FlowerApiController : BaseController
|
||||
var flower = database.Flowers.SingleOrDefault(f => f.Id == id && f.OwnerId == user.Id);
|
||||
if (flower == null)
|
||||
{
|
||||
SaveDatabase();
|
||||
return NotFound(id);
|
||||
}
|
||||
if (photo.Length > 0)
|
||||
@@ -386,7 +384,6 @@ public class FlowerApiController : BaseController
|
||||
var file = WrapFormFile(photo);
|
||||
if (file == null)
|
||||
{
|
||||
SaveDatabase();
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
@@ -406,30 +403,32 @@ public class FlowerApiController : BaseController
|
||||
};
|
||||
database.Records.Add(record);
|
||||
}
|
||||
|
||||
var cover = new PhotoItem
|
||||
{
|
||||
FlowerId = id,
|
||||
Record = record,
|
||||
FileType = file.FileType,
|
||||
FileName = file.Filename,
|
||||
Path = file.Path,
|
||||
DateUploadUnixTime = now
|
||||
};
|
||||
database.Photos.Add(cover);
|
||||
SaveDatabase();
|
||||
|
||||
try
|
||||
{
|
||||
await WriteToFile(user.Id, id, file);
|
||||
await ExecuteTransaction(async token =>
|
||||
{
|
||||
var cover = new PhotoItem
|
||||
{
|
||||
FlowerId = id,
|
||||
RecordId = record.Id,
|
||||
FileType = file.FileType,
|
||||
FileName = file.Filename,
|
||||
Path = file.Path,
|
||||
DateUploadUnixTime = now
|
||||
};
|
||||
AddPhotoItem(cover);
|
||||
|
||||
await WriteToFile(user.Id, id, file, token);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveDatabase();
|
||||
return Problem(ex.ToString(), "api/flower/add_cover");
|
||||
// TODO: Logger
|
||||
}
|
||||
}
|
||||
SaveDatabase();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
Reference in New Issue
Block a user