public void SaveItem(CatalogItemModel model) { var item = model.Source; if (model.Picture != null) { string extension = ContentTypes.GetExtensionFromContentType(model.PictureContentType); item.PictureFileName = $"{DateTime.UtcNow.Ticks}{extension}"; } var provider = new SqlServerProvider(ConnectionString); if (item.Id == 0) { // New item.Id = GenerateId(); provider.InsertCatalogItem(item.Id, item.Name, item.Description, item.PictureFileName, item.Price, item.CatalogTypeId, item.CatalogBrandId, item.IsDisabled); provider.InsertCatalogImage(item.Id, model.Picture); } else { // Update if (model.Picture != null) { provider.UpdateCatalogImage(item.Id, model.Picture); } provider.UpdateCatalogItem(item.Id, item.Name, item.Description, item.PictureFileName, item.Price, item.CatalogTypeId, item.CatalogBrandId, item.IsDisabled); } }