Example #1
0
        public ActionResult Edit(BoxCreateDTO req)
        {
            Response res = new Response();

            if (ModelState.IsValid)
            {
                try
                {
                    if (req.Id > 0)
                    {
                        res.Data = _boxRepository.Update(req);
                    }
                    else
                    {
                        res.Data = _boxRepository.Create(req);
                    }
                }
                catch (Exception ex)
                {
                    res.Message = ex.Message;
                }
            }
            else
            {
                res.Data    = false;
                res.Message = string.Join(",", ModelState
                                          .SelectMany(ms => ms.Value.Errors)
                                          .Select(e => e.ErrorMessage));
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public bool Update(BoxCreateDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                bool  result = true;
                R_Box model  = new R_Box()
                {
                    Name            = req.Name,
                    Description     = req.Description,
                    Id              = req.Id,
                    R_Restaurant_Id = req.Restaurant,
                    R_Area_Id       = req.RestaurantArea
                };

                result = db.Update(model);
                return(result);
            }
        }
Example #3
0
        public bool Create(BoxCreateDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                bool  result = true;
                R_Box model  = new R_Box()
                {
                    Name            = req.Name,
                    Description     = req.Description,
                    R_Area_Id       = req.RestaurantArea,
                    R_Restaurant_Id = req.Restaurant
                };

                if (db.Insert(model) == null)
                {
                    result = false;
                }

                return(result);
            }
        }
Example #4
0
        public BoxCreateDTO GetModel(int id)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                BoxCreateDTO result = null;
                var          model  = db.Queryable <R_Box>().InSingle(id);

                if (model != null)
                {
                    result = new BoxCreateDTO()
                    {
                        Id             = model.Id,
                        Name           = model.Name,
                        Description    = model.Description,
                        RestaurantArea = model.R_Area_Id,
                        Restaurant     = model.R_Restaurant_Id
                    };
                }

                return(result);
            }
        }