Exemplo n.º 1
0
        public ActionResult Edit(AreaCreateDTO req)
        {
            Response res = new Response();

            if (ModelState.IsValid)
            {
                try
                {
                    if (req.Id > 0)
                    {
                        res.Data = _areaRepository.Update(req);
                    }
                    else
                    {
                        res.Data = _areaRepository.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));
        }
Exemplo n.º 2
0
        public bool Create(AreaCreateDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                bool   result = true;
                R_Area model  = new R_Area()
                {
                    Name            = req.Name,
                    Description     = req.Description,
                    R_Restaurant_Id = req.Restaurant,
                    ServerRate      = req.ServerRate == null ? 0 : req.ServerRate
                };

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

                return(result);
            }
        }
Exemplo n.º 3
0
        public bool Update(AreaCreateDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                bool result = true;
                try
                {
                    db.BeginTran();

                    R_Area model = new R_Area()
                    {
                        Name            = req.Name,
                        Description     = req.Description,
                        Id              = req.Id,
                        R_Restaurant_Id = req.Restaurant,
                        ServerRate      = req.ServerRate == null ? 0 : req.ServerRate
                    };

                    db.Update(model);

                    if (req.IsUpdate)
                    {
                        db.Update <R_Table>(new
                        {
                            ServerRate = model.ServerRate
                        }, p => p.R_Area_Id == model.Id);
                    }

                    db.CommitTran();
                }
                catch (Exception)
                {
                    db.RollbackTran();
                    result = false;
                }

                return(result);
            }
        }
Exemplo n.º 4
0
        public AreaCreateDTO GetModel(int id)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                AreaCreateDTO result = null;
                var           model  = db.Queryable <R_Area>().InSingle(id);

                if (model != null)
                {
                    result = new AreaCreateDTO()
                    {
                        Id          = model.Id,
                        Name        = model.Name,
                        Description = model.Description,
                        Restaurant  = model.R_Restaurant_Id,
                        ServerRate  = model.ServerRate.Value
                    };
                }

                return(result);
            }
        }