예제 #1
0
        public ActionResult Edit(StallsCreateDTO req)
        {
            Response res = new Response();

            if (ModelState.IsValid)
            {
                try
                {
                    if (req.Id > 0)
                    {
                        res.Data = _stallsRepository.Update(req);
                    }
                    else
                    {
                        res.Data = _stallsRepository.Create(req);
                    }
                }
                catch (Exception ex)
                {
                    res.Message = ex.InnerException.Message;
                }
            }
            else
            {
                res.Data    = false;
                res.Message = string.Join(",", ModelState
                                          .SelectMany(ms => ms.Value.Errors)
                                          .Select(e => e.ErrorMessage));
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public bool Create(StallsCreateDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                bool    result = true;
                R_Stall model  = new R_Stall()
                {
                    Name        = req.Name,
                    Description = req.Description,
                    Print_Id    = req.Print_Id
                };

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

                return(result);
            }
        }
예제 #3
0
        public StallsCreateDTO GetModel(int id, int?billType = null)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                StallsCreateDTO result = null;
                if (id == 0)
                {
                    return(result);
                }

                var data = db.Queryable <R_Stall>().InSingle(id);

                if (data != null)
                {
                    result = new StallsCreateDTO()
                    {
                        Id          = data.Id,
                        Name        = data.Name,
                        Description = data.Description,
                        Print_Id    = data.Print_Id,
                    };

                    if (billType.HasValue)
                    {
                        var cyxmDks = db.Queryable <R_ProjectStall>()
                                      .Where(p => p.R_Stall_Id == result.Id && p.BillType == billType.Value)
                                      .ToList();
                        result.ProjectStallList = cyxmDks;
                    }
                    else
                    {
                        var cyxmAllDks = db.Queryable <R_ProjectStall>()
                                         .Where(p => p.R_Stall_Id == result.Id)
                                         .ToList();
                        result.ProjectStallList = cyxmAllDks;
                    }
                }
                return(result);
            }
        }
예제 #4
0
 public bool Update(StallsCreateDTO req)
 {
     using (var db = new SqlSugarClient(Connection))
     {
         bool    result = true;
         R_Stall model  = new R_Stall()
         {
             Id          = req.Id,
             Name        = req.Name,
             Description = req.Description
         };
         //result = db.Update(model);
         result = db.Update <R_Stall>(
             new
         {
             Name         = req.Name,
             Description  = req.Description,
             Print_Id     = req.Print_Id,
             R_Company_Id = req.R_Company_Id,
         }, x => x.Id == req.Id);
         return(result);
     }
 }