예제 #1
0
        public async Task <JsonResult> SaveDayComplex(int ComplexId, DateTime daydate, bool enabled)
        {
            //daydate = DateTime.Now;
            if (ModelState.IsValid)
            {
                DayComplex proto = new DayComplex()
                {
                    ComplexId = ComplexId, Date = daydate
                };
                this.AssignCompantAttr(proto);
                DayComplex exsistdd = _dayDishesRepo.SelectComplexSingleOrDefault(proto);
                // this.AssignCompantAttr(exsistdd);
                try
                {
                    if (enabled)
                    {
                        if (exsistdd != null)
                        {
                            //something wrong
                        }
                        else
                        {
                            await _context.AddAsync(proto);
                        }
                    }
                    else
                    {
                        var ordered = _context.UserDayComplex.Where
                                          (x => x.ComplexId == proto.ComplexId && x.Date == proto.Date && x.CompanyId == proto.CompanyId).ToList();
                        if (ordered.Count() > 0)
                        {
                            //you can't delete this complex
                            return(Json(new { res = "FAIL", reason = "Deleting in db" }));
                        }
                        else
                        {
                            _context.Remove(exsistdd);
                        }
                    }
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Save DayDish");
                    return(Json(-1));
                }
            }

            //return Json(DishId);
            return(Json(ComplexId));
        }
예제 #2
0
 public DayComplex SelectComplexSingleOrDefault(DayComplex src)
 {
     return(_context.DayComplex.SingleOrDefault(dd => dd.ComplexId == src.ComplexId && dd.Date == src.Date && dd.HotelId == src.HotelId));
 }