Exemplo n.º 1
0
        public static List <SouvenirViewModel> GetListSouvenir(SouvenirViewModel paramSearch)
        {
            List <SouvenirViewModel> result = new List <SouvenirViewModel>();

            if (paramSearch.mUnitId != 0)
            {
                paramSearch.unitId = paramSearch.mUnitId;
            }

            using (var context = new MarkomApplicationDBEntities())
            {
                var res = context.spSouSearch(paramSearch.code, paramSearch.name, paramSearch.unitId, paramSearch.createDate2, paramSearch.createBy);

                List <SouvenirViewModel> comList = res.Select(c => new SouvenirViewModel
                {
                    id         = c.id,
                    code       = c.code,
                    name       = c.name,
                    unitName   = c.unit_name,
                    createDate = c.create_date,
                    createBy   = c.create_by
                }).ToList();

                result = comList;
            }

            return(result);
        }
Exemplo n.º 2
0
        public ActionResult EditDataSouvenir(SouvenirViewModel paramEditSou)
        {
            if (ModelState.IsValid)
            {
                //update data manual createby and createdate
                paramEditSou.updateBy   = "Administator";
                paramEditSou.updateDate = DateTime.Now;

                int?nameV = SouvenirDataAccess.NameValidation(paramEditSou.name);

                if (nameV <= 1)
                {
                    if (SouvenirDataAccess.UpdateSouvenir(paramEditSou))
                    {
                        return(Json(new { success = true, message = SouvenirDataAccess.Message }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = SouvenirDataAccess.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { success = false, message = "Sou name " + paramEditSou.name + " is exist !" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, message = "Wajib menginputkan semua kotak bertanda bintang" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public static SouvenirViewModel GetById(int id)
        {
            SouvenirViewModel result = new 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 SouvenirViewModel
                {
                    Id = s.Id,
                    Code = s.Code,
                    Name = s.Name,
                    Description = s.Description,
                    Quantity = s.Quantity,
                    M_Unit_Id = s.M_Unit_Id,
                    Unit = u.Name,
                    Is_Delete = s.Is_Delete,
                    Create_By = s.Create_By,
                    Create_Date = s.Create_Date,
                }).FirstOrDefault();
            }
            return(result);
        }
Exemplo n.º 4
0
        public static List <SouvenirViewModel> Filter(SouvenirViewModel entity)
        {
            List <SouvenirViewModel> result = new List <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.Code.Contains(entity.Code) || s.Name.Contains(entity.Name) || s.M_Unit_Id.ToString() == entity.Unit || s.Create_By.Contains(entity.Create_By) || s.Create_Date == entity.Create_Date
                          select new SouvenirViewModel
                {
                    Id = s.Id,
                    Code = s.Code,
                    Name = s.Name,
                    Description = s.Description,
                    Quantity = s.Quantity,
                    M_Unit_Id = s.Id,
                    Unit = u.Name,
                    Is_Delete = s.Is_Delete,

                    Create_By = s.Create_By,
                    Create_Date = s.Create_Date
                })
                         .ToList();
            }
            return(result);
        }
Exemplo n.º 5
0
        //UPDATE Souvenir
        public static bool UpdateSouvenir(SouvenirViewModel paramEditEmp)
        {
            bool result = true;

            try
            {
                using (MarkomApplicationDBEntities db = new MarkomApplicationDBEntities())
                {
                    db.spSouUpdate(
                        paramEditEmp.id
                        , paramEditEmp.name
                        , paramEditEmp.mUnitId
                        , paramEditEmp.description
                        , paramEditEmp.updateBy
                        , paramEditEmp.updateDate
                        );
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
                //throw;
            }
            return(result);
        }
Exemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            //ViewBag.Unit = new SelectList(SouvenirRepo.Get(), "Id", "Name");
            SouvenirViewModel model = SouvenirRepo.GetById(id);

            return(PartialView("_Delete", model));
        }
Exemplo n.º 7
0
        //List markom selesai

        public static ResultResponse Update(SouvenirViewModel entity)
        {
            ResultResponse result = new ResultResponse();

            try
            {
                using (var db = new MarComContext())
                {
                    if (entity.Id == 0)
                    {
                        M_Souvenir souvenir = new M_Souvenir();
                        //souvenir.Code = entity.Code;
                        souvenir.Code        = entity.Code;
                        souvenir.Name        = entity.Name;
                        souvenir.Description = entity.Description;
                        souvenir.Quantity    = entity.Quantity;
                        souvenir.M_Unit_Id   = entity.M_Unit_Id;
                        souvenir.Is_Delete   = entity.Is_Delete;

                        souvenir.Create_By   = "Admin";
                        souvenir.Create_Date = DateTime.Now;

                        db.M_Souvenir.Add(souvenir);
                        db.SaveChanges();
                    }
                    else
                    {
                        M_Souvenir souvenir = db.M_Souvenir.Where(s => s.Id == entity.Id).FirstOrDefault();
                        if (souvenir != null)
                        {
                            souvenir.Code        = entity.Code;
                            souvenir.Name        = entity.Name;
                            souvenir.Description = entity.Description;
                            souvenir.Quantity    = entity.Quantity;
                            souvenir.M_Unit_Id   = entity.M_Unit_Id;
                            souvenir.Is_Delete   = entity.Is_Delete;

                            souvenir.Update_By   = "Admin";
                            souvenir.Update_Date = DateTime.Now;

                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            UserViewModel model2 = SouvenirRequestRepo.GetIdByName(User.Identity.Name);

            ViewBag.Unit = new SelectList(UnitRepo.Get(), "Id", "Name");
            SouvenirViewModel model = SouvenirRepo.GetById(id);

            if (model2.Role == "Staff" || model2.Role == "Admin")
            {
                return(PartialView("_Edit", model));
            }
            else
            {
                return(new RedirectToRouteResult(new RouteValueDictionary(new { controller = "AccessDenied", action = "Index" })));
            }
        }
Exemplo n.º 9
0
        //GET DETAIL Souvenir
        public static SouvenirViewModel GetDetailSouvenirById(int paramSouvenirId)
        {
            SouvenirViewModel result = new SouvenirViewModel();

            using (var db = new MarkomApplicationDBEntities())
            {
                var res = db.spSouDetailByID(paramSouvenirId);

                result = res.Select(c => new SouvenirViewModel
                {
                    id          = c.id,
                    code        = c.code,
                    name        = c.name,
                    mUnitId     = c.m_unit_id,
                    unitName    = c.unit_name,
                    description = c.description
                }).FirstOrDefault();
            }

            return(result);
        }
Exemplo n.º 10
0
 public ActionResult Edit(SouvenirViewModel model)
 {
     if (ModelState.IsValid)
     {
         model.Update_By = User.Identity.Name;
         ResultResponse result = SouvenirRepo.Update(model);
         return(Json(new
         {
             success = result.Success,
             message = result.Message
         }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(new
         {
             success = false,
             message = "A required column is still blank, Please fill correctly",
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 11
0
        public static string CreateSouvenir(SouvenirViewModel paramDataSou)
        {
            string latestSaveCode = string.Empty;

            using (var db = new MarkomApplicationDBEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        m_souvenir c = new m_souvenir();
                        c.code        = SouvenirCode();
                        c.name        = paramDataSou.name;
                        c.m_unit_id   = paramDataSou.mUnitId;
                        c.description = paramDataSou.description;
                        c.is_delete   = paramDataSou.isDelete;
                        c.create_by   = paramDataSou.createBy;
                        c.create_date = paramDataSou.createDate;

                        db.m_souvenir.Add(c);
                        db.SaveChanges();
                        dbContextTransaction.Commit();

                        //get latest save code
                        latestSaveCode = c.code;
                    }
                    catch (Exception ex)
                    {
                        Message = ex.Message;
                        dbContextTransaction.Rollback();
                        //throw;
                    }
                }
            }

            return(latestSaveCode);
        }
Exemplo n.º 12
0
        public ActionResult CreateDataSouvenir(SouvenirViewModel paramAddSou)
        {
            if (ModelState.IsValid)
            {
                //is delete default value
                paramAddSou.isDelete = false;
                //update data manual createby and createdate
                paramAddSou.createBy   = "Administator";
                paramAddSou.createDate = DateTime.Now;


                int?nameV = SouvenirDataAccess.NameValidation(paramAddSou.name);

                if (nameV == 0)
                {
                    string latestCode = SouvenirDataAccess.CreateSouvenir(paramAddSou);

                    if (latestCode != "")
                    {
                        return(Json(new { success = true, latestCode, message = SouvenirDataAccess.Message }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = SouvenirDataAccess.Message }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { success = false, message = "Souvenir name " + paramAddSou.name + " is exist !" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, message = "Wajib menginputkan semua kotak bertanda bintang" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 13
0
        public ActionResult Show(int id)
        {
            SouvenirViewModel model = SouvenirRepo.GetById(id);

            return(PartialView("_Show", model));
        }
Exemplo n.º 14
0
        public ActionResult Index(SouvenirViewModel paramSearch)
        {
            List <SouvenirViewModel> listSearchSou = SouvenirDataAccess.GetListSouvenir(paramSearch);

            return(PartialView(listSearchSou));
        }
Exemplo n.º 15
0
        //List markom selesai

        public static ResultResponse Update(SouvenirViewModel entity)
        {
            ResultResponse result = new ResultResponse();

            try
            {
                using (var db = new MarComContext())
                {
                    if (entity.Id == 0)
                    {
                        bool notExist = db.M_Souvenir.Any(ms => ms.Name.Equals(entity.Name));
                        if (notExist)
                        {
                            result.Success = false;
                            result.Message = "Souvenir with name " + entity.Name + " already Exist !";
                        }
                        else
                        {
                            M_Souvenir souvenir = new M_Souvenir();
                            souvenir.Code        = entity.Code;
                            souvenir.Name        = entity.Name;
                            souvenir.Description = entity.Description;
                            souvenir.Quantity    = entity.Quantity;
                            souvenir.M_Unit_Id   = entity.M_Unit_Id;
                            souvenir.Is_Delete   = entity.Is_Delete;

                            souvenir.Create_By   = entity.Create_By;
                            souvenir.Create_Date = DateTime.Now;

                            db.M_Souvenir.Add(souvenir);

                            db.SaveChanges();
                            result.Message = "Data Saved ! New Souvenier has been add with code " + entity.Code;
                        }
                    }
                    else
                    {
                        M_Souvenir souvenir = db.M_Souvenir.Where(s => s.Id == entity.Id).FirstOrDefault();
                        if (souvenir != null)
                        {
                            bool notExist = db.M_Souvenir.Any(ms => ms.Name.Equals(entity.Name) && ms.Code != entity.Code);
                            if (notExist)
                            {
                                result.Success = false;
                                result.Message = "Souvenir with name " + entity.Name + " already Exist !";
                            }
                            else
                            {
                                souvenir.Name        = entity.Name;
                                souvenir.Description = entity.Description;
                                souvenir.Quantity    = entity.Quantity;
                                souvenir.M_Unit_Id   = entity.M_Unit_Id;
                                //souvenir.Is_Delete = entity.Is_Delete;

                                souvenir.Update_By   = entity.Update_By;
                                souvenir.Update_Date = DateTime.Now;

                                db.SaveChanges();
                                result.Message = "Data Update ! Data Souvenir has been updated";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 16
0
 public ActionResult Filter(SouvenirViewModel model)
 {
     return(PartialView("_List", SouvenirRepo.Filter(model)));
 }
Exemplo n.º 17
0
 public ActionResult Delete(SouvenirViewModel model)
 {
     return(RedirectToAction("index"));
 }