Exemplo n.º 1
0
 public ActionResult Edit(SalaryComponentViewModel model)
 {
     if (ModelState.IsValid)
     {
         Responses responses = (SalaryComponentRepo.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);
 }
Exemplo n.º 2
0
 public ActionResult Create(SalaryComponentViewModel model)
 {
     if (ModelState.IsValid)
     {
         Responses responses = SalaryComponentRepo.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 = ModelState.ToString() }, JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 3
0
        public static Responses Update(SalaryComponentViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new PayrollContext())
                {
                    if (entity.Id != 0)
                    {
                        SalaryComponent division = db.SalaryComponent.Where(o => o.Id == entity.Id).FirstOrDefault();
                        if (division != null)
                        {
                            division.Code        = entity.Code;
                            division.Description = entity.Description;
                            division.Period      = entity.Period;
                            division.Type        = entity.Type;
                            division.IsActivated = entity.IsActivated;
                            division.ModifyBy    = "Asyam";
                            division.ModifyDate  = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        SalaryComponent division = new SalaryComponent();
                        division.Code        = entity.Code;
                        division.Description = entity.Description;
                        division.Period      = entity.Period;
                        division.Type        = entity.Type;
                        division.IsActivated = entity.IsActivated;
                        division.CreateBy    = "Asyam";
                        division.CreateDate  = DateTime.Now;
                        db.SalaryComponent.Add(division);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
Exemplo n.º 4
0
        public static Responses Update(SalaryComponentViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new PayrollContext())
                {
                    if (entity.Id != 0)
                    {
                        SalaryComponent salarycomponent = db.SalaryComponent.Where(o => o.Id == entity.Id).FirstOrDefault();
                        if (salarycomponent != null)
                        {
                            salarycomponent.Code         = entity.Code;
                            salarycomponent.Description  = entity.Description;
                            salarycomponent.Period       = entity.Period;
                            salarycomponent.Type         = entity.Type;
                            salarycomponent.IsActivated  = entity.IsActivated;
                            salarycomponent.ModifiedBy   = "Ryan";
                            salarycomponent.ModifiedDate = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        SalaryComponent salarycomponent = new SalaryComponent();
                        salarycomponent.Code        = entity.Code;
                        salarycomponent.Description = entity.Description;
                        salarycomponent.Period      = entity.Period;
                        salarycomponent.Type        = entity.Type;
                        salarycomponent.IsActivated = entity.IsActivated;
                        salarycomponent.CreatedBy   = "Ryan";
                        salarycomponent.CreatedDate = DateTime.Now;
                        db.SalaryComponent.Add(salarycomponent);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
Exemplo n.º 5
0
        public static SalaryComponentViewModel GetById(int id)
        {
            SalaryComponentViewModel result = new SalaryComponentViewModel();

            using (var db = new PayrollContext())
            {
                result = (from d in db.SalaryComponent
                          where d.Id == id
                          select new SalaryComponentViewModel
                {
                    Id = d.Id,
                    Code = d.Code,
                    Description = d.Description,
                    Period = d.Period,
                    Type = d.Type,
                    IsActivated = d.IsActivated
                }).FirstOrDefault();
            }
            return(result);
        }
 // PUT api/<controller>/5
 public Responses Put(int id, [FromBody] SalaryComponentViewModel entity)
 {
     entity.Id = id;
     return(SalaryComponentRepo.Update(entity));
 }
 // POST api/<controller>
 public Responses Post([FromBody] SalaryComponentViewModel entity)
 {
     return(SalaryComponentRepo.Update(entity));
 }