コード例 #1
0
        public ActionResult Create()
        {
            M_SouvenirViewModel model = new M_SouvenirViewModel();

            model.Code = M_SouvenirRepo.GetNewCode();
            return(PartialView("_Create", model));
        }
コード例 #2
0
        public static M_SouvenirViewModel GetById(int id)
        {
            M_SouvenirViewModel result = new M_SouvenirViewModel();

            using (var db = new MarcomContext())
            {
                result = (from s in db.m_souvenir
                          join u in db.m_unit on
                          s.m_unit_id equals u.id
                          where s.id == id
                          select new M_SouvenirViewModel
                {
                    Id = s.id,
                    Code = s.code,
                    Name = s.name,
                    Description = s.description,
                    mUnitId = s.m_unit_id,
                    unitName = u.name,
                    Created_by = s.created_by,
                    Created_date = s.created_date,
                    isDelete = s.is_delete
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #3
0
        // POST: api/M_Souvenirs
        public Responses Post([FromBody] M_SouvenirViewModel entity)
        {
            Responses result = new Responses();

            if (ModelState.IsValid)
            {
                result = M_SouvenirRepo.Update(entity);
            }
            else
            {
                result.Success = false;
            }
            return(result);
        }
コード例 #4
0
        public static Responses Update(M_SouvenirViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_souvenir souvenir = db.m_souvenir.Where(o => o.id == entity.Id).FirstOrDefault();
                        if (souvenir != null)
                        {
                            souvenir.id           = entity.Id;
                            souvenir.code         = entity.Code;
                            souvenir.name         = entity.Name;
                            souvenir.description  = entity.Description;
                            souvenir.m_unit_id    = entity.mUnitId;
                            souvenir.is_delete    = entity.isDelete;
                            souvenir.updated_by   = "Asyam";
                            souvenir.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_souvenir souvenir = new m_souvenir();
                        souvenir.id           = entity.Id;
                        souvenir.code         = entity.Code;
                        souvenir.name         = entity.Name;
                        souvenir.description  = entity.Description;
                        souvenir.m_unit_id    = entity.mUnitId;
                        souvenir.is_delete    = false;
                        souvenir.created_by   = "Asyam";
                        souvenir.created_date = DateTime.Now;
                        db.m_souvenir.Add(souvenir);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
コード例 #5
0
 // PUT: api/M_Souvenirs/5
 public Responses Put(int id, [FromBody] M_SouvenirViewModel entity)
 {
     entity.Id = id;
     return(M_SouvenirRepo.Update(entity));
 }