public async Task QuickSaveAsync(RestaurantQuickSaveDTO entity) { var id = entity.Id == null ? new MongoDB.Bson.ObjectId() : new MongoDB.Bson.ObjectId(entity.Id); var r = await FirstOrDefaultAsync(x => x.Id == id); bool isNew = false; if (r == null) { r = new Restaurant(); isNew = true; r.Categories = new List <Categories>(); r.Product = new List <Product>(); r.Promotion = new List <Promotion>(); } r.Name = entity.Name; r.Email = entity.Email; if (entity.Password != "0") { r.Password = PasswordHash.GetPasswordHash(entity.Password); } r.UserName = entity.UserName; r.isActive = entity.isActive; r.isPromo = entity.isPromo; if (!string.IsNullOrEmpty((string)entity.ContractId)) { r.ContractId = new ObjectId((string)entity.ContractId); } if (entity.Product != null) { foreach (var item in entity.Product) { r.Product.Add(new Product() { Id = ObjectId.GenerateNewId(), Description = item.Description, DueDate = item.DueDate, Status = StatusType.Approved }); } } if (entity.Promotion != null) { foreach (var item in entity.Promotion) { try { var tmpProd = entity.Product.FirstOrDefault(z => z.Id.ToString() == item.ProductId.ToString()); var prodId = r.Product.FirstOrDefault(x => x.Description == tmpProd.Description); r.Promotion.Add(new Promotion() { Id = ObjectId.GenerateNewId(), Status = StatusType.Approved, Claim = item.Claim, ProductId = prodId.Id }); } catch (Exception ex) { throw new HttpStatusCodeException(StatusCodes.Status404NotFound, ex.Message); } } } if (entity.Categories != null) { foreach (var item in entity.Categories) { r.Categories.Add(new Categories() { Id = ObjectId.GenerateNewId(), Definition = item.Definition }); } } r.Info = (new Info() { Adress = new Adress { AdressDetail = entity.Adress, Latitude = entity.Latitude, Longitude = entity.Longitude } }); if (isNew) { await Add(r); } else { await UpdateAsync(r); } }
public async Task QuickSave([FromBody] RestaurantQuickSaveDTO item) { await _restaurantService.QuickSaveAsync(item); }