コード例 #1
0
        public static M_CompanyViewModel GetById(int id)
        {
            M_CompanyViewModel result = new M_CompanyViewModel();

            using (var db = new MarcomContext())
            {
                result = (from c in db.m_company
                          where c.id == id
                          select new M_CompanyViewModel
                {
                    Id = c.id,
                    Code = c.code,
                    Name = c.name,
                    Address = c.address,
                    Phone = c.phone,
                    Email = c.email,
                    IsDelete = c.is_delete,
                    CreatedBy = c.created_by,
                    CreatedDate = c.created_date,
                    UpdatedBy = c.updated_by,
                    UpdatedDate = c.updated_date
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #2
0
        // POST: api/M_Companies
        public Responses Post([FromBody] M_CompanyViewModel entity)
        {
            Responses result = new Responses();

            if (ModelState.IsValid)
            {
                result = M_CompanyRepo.Update(entity);
            }
            else
            {
                result.Success = false;
            }
            return(result);
        }
コード例 #3
0
 public ActionResult Edit(M_CompanyViewModel model)
 {
     if (ModelState.IsValid)
     {
         Responses responses = (M_CompanyRepo.Update(model));
         if (responses.Success)
         {
             return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { success = false, message = responses.Message }, JsonRequestBehavior.AllowGet));
         }
     }
     return(Json(new { success = false, message = "Invalid" }, JsonRequestBehavior.AllowGet));
 }
コード例 #4
0
        public static Responses Update(M_CompanyViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_company company = db.m_company.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (company != null)
                        {
                            company.code         = entity.Code;
                            company.name         = entity.Name;
                            company.address      = entity.Address;
                            company.phone        = entity.Phone;
                            company.email        = entity.Email;
                            company.is_delete    = entity.IsDelete;
                            company.updated_by   = "Andra";
                            company.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_company company = new m_company();
                        company.code         = GetNewCode();
                        company.name         = entity.Name;
                        company.address      = entity.Address;
                        company.phone        = entity.Phone;
                        company.email        = entity.Email;
                        company.is_delete    = false;
                        company.created_by   = "Andra";
                        company.created_date = DateTime.Now;
                        db.m_company.Add(company);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }