public async Task <int> CreateAsync(CostCalculationGarment model) { int Created = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { do { model.Code = CodeGenerator.Generate(); await CustomCodeGenerator(model); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); costCalculationGarmentLogic.Create(model); if (model.ImagePath != null) { model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); } costCalculationGarmentLogic.Create(model); Created = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <int> CreateAsync(CostCalculationGarment model) { do { model.Code = CodeGenerator.Generate(); await CustomCodeGenerator(model); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); costCalculationGarmentLogic.Create(model); if (model.ImagePath != null) { model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); } model.IsValidated = false; costCalculationGarmentLogic.Create(model); return(await DbContext.SaveChangesAsync()); }