Example #1
0
        public void Delete(T entity)
        {
            using (ERPEntities entities = new ERPEntities())
            {
                try
                {
                    entities.Entry(entity).State = EntityState.Deleted;
                    entities.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    Exception raise = e;
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        foreach (var ve in eve.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           eve.Entry.Entity.ToString(),
                                                           ve.ErrorMessage);

                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
        }
Example #2
0
        public bool SaveAdminSetUp(long id, AdminSetUpModel model)
        {
            if (model == null)
            {
                throw new Exception("Admin SetUp data missing!");
            }
            AdminSetUp adminSetUp = ObjectConverter <AdminSetUpModel, AdminSetUp> .Convert(model);

            if (id > 0)
            {
                adminSetUp = adminSetUpRepository.AdminSetUps.FirstOrDefault(x => x.AdminId == id);
                if (adminSetUp == null)
                {
                    throw new Exception("Admin SetUp not found!");
                }
                adminSetUp.ModifiedBy   = System.Web.HttpContext.Current.User.Identity.Name;
                adminSetUp.ModifiedDate = DateTime.Now;
            }
            else
            {
                adminSetUp.CreatededBy = System.Web.HttpContext.Current.User.Identity.Name;
                adminSetUp.CreatedDate = DateTime.Now;
            }

            adminSetUp.Id       = model.Id;
            adminSetUp.IsActive = model.IsActive;

            adminSetUpRepository.Entry(adminSetUp).State = adminSetUp.AdminId == 0 ? EntityState.Added : EntityState.Modified;
            return(adminSetUpRepository.SaveChanges() > 0);
        }
Example #3
0
        public bool SaveYearlyHoliday(int id, YearlyHolidayModel model)
        {
            if (model == null)
            {
                throw new Exception("Holiday data missing");
            }
            YearlyHoliday yearlyHoliday = ObjectConverter <YearlyHolidayModel, YearlyHoliday> .Convert(model);


            if (id > 0)
            {
                yearlyHoliday = yearlyHolidayRepository.YearlyHolidays.FirstOrDefault(x => x.YearlyHolidayId == id);
                if (yearlyHoliday == null)
                {
                    throw new Exception("Holiday Data not found!");
                }

                //yearlyHoliday.ModifiedDate = DateTime.Now;
                //yearlyHoliday.ModifedBy = "";
                //employeeRepository.Entry(employee).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                yearlyHoliday.CreatedBy   = System.Web.HttpContext.Current.User.Identity.Name;
                yearlyHoliday.CreatedDate = DateTime.Now;
            }

            yearlyHoliday.HolidayDate     = model.HolidayDate;
            yearlyHoliday.HolidayCategory = model.HolidayCategory;
            yearlyHoliday.Purpose         = model.Purpose;

            yearlyHolidayRepository.Entry(yearlyHoliday).State = yearlyHoliday.YearlyHolidayId == 0 ? EntityState.Added : EntityState.Modified;
            return(yearlyHolidayRepository.SaveChanges() > 0);
        }
Example #4
0
 public ActionResult Edit([Bind(Include = "UserMenuId,UserId,MenuId,SubMenuId,IsView,IsAdd,IsUpdate,IsDelete,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate,IsActive")] UserMenu userMenu)
 {
     if (ModelState != null)
     {
         UserMenu oldUserMenu = db.UserMenus.FirstOrDefault(x => x.UserMenuId == userMenu.UserMenuId);
         if (oldUserMenu == null)
         {
             throw new Exception("User Menu not found");
         }
         oldUserMenu.UserId          = userMenu.UserId;
         oldUserMenu.MenuId          = userMenu.MenuId;
         oldUserMenu.SubMenuId       = userMenu.SubMenuId;
         oldUserMenu.IsView          = userMenu.IsView;
         oldUserMenu.IsAdd           = userMenu.IsAdd;
         oldUserMenu.IsUpdate        = userMenu.IsUpdate;
         oldUserMenu.IsDelete        = userMenu.IsDelete;
         oldUserMenu.ModifiedBy      = System.Web.HttpContext.Current.User.Identity.Name;
         oldUserMenu.ModifiedDate    = DateTime.Now;
         oldUserMenu.IsActive        = userMenu.IsActive;
         db.Entry(oldUserMenu).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ddlMenu    = new SelectList(db.Menus, "MenuId", "Name", userMenu.MenuId);
     ViewBag.ddlSubMenu = new SelectList(db.SubMenus, "SubMenuId", "Name", userMenu.SubMenuId);
     return(View(userMenu));
 }
Example #5
0
 public void Delete(T entity)
 {
     using (ERPEntities entities = new ERPEntities())
     {
         entities.Entry(entity).State = EntityState.Deleted;
         entities.SaveChanges();
     }
 }
Example #6
0
 public void Update(T entity)
 {
     using (ERPEntities entities = new ERPEntities())
     {
         entities.Entry(entity).State = EntityState.Modified;
         entities.SaveChanges();
     }
 }
Example #7
0
        public bool SaveKttlCustomer(long id, CustomerModel model)
        {
            bool result = false;

            try
            {
                Customer customer = ObjectConverter <CustomerModel, Customer> .Convert(model);

                if (id > 0)
                {
                    customer.ModifiedDate = DateTime.Now;
                    customer.ModifiedBy   = System.Web.HttpContext.Current.User.Identity.Name;
                }
                else
                {
                    customer.CreatedBy   = System.Web.HttpContext.Current.User.Identity.Name;
                    customer.CreatedDate = DateTime.Now;
                }
                customer.CustomerId   = model.CustomerId;
                customer.CustomerType = model.CustomerType;
                customer.CustomerName = model.CustomerName;
                customer.AddressOne   = model.AddressOne;
                //customer.FiscalYear = model.FiscalYear;
                customer.Telephone         = model.Telephone;
                customer.MobileNo          = model.MobileNo;
                customer.TIN               = model.TIN;
                customer.ContactPersonName = model.ContactPersonName;
                customer.ConcatPersonEmail = model.ConcatPersonEmail;
                customer.AddressTwo        = model.AddressTwo;
                customer.DateOfBirth       = model.DateOfBirth;
                customer.Nationality       = model.Nationality;
                customer.Email             = model.Email;
                customer.Designation       = model.Designation;
                customer.Division          = model.Division;
                customer.District          = model.District;
                //customer.LogoUrl = model.LogoUrl;
                //customer.ImageUrl = model.ImageUrl;
                customer.Remarks = model.Remarks;
                context.Entry(customer).State = customer.OID == 0 ? EntityState.Added : EntityState.Modified;
                result = context.SaveChanges() > 0;
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult errors in ex.EntityValidationErrors)
                {
                    foreach (DbValidationError validationError in errors.ValidationErrors)
                    {
                        // get the error message
                        string errorMessage = validationError.ErrorMessage;
                        result = false;
                    }
                }
            }
            return(result);
        }
 public ActionResult Edit(DictionaryType model)
 {
     if (ModelState.IsValid)
     {
         //把存储状态修改成“modified”
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Example #9
0
 public ActionResult AddCountry(country country)
 {
     if (country.id > 0)
     {
         db.Entry(country).State = EntityState.Modified;
     }
     else
     {
         var newId = db.countries.Max(x => x.id + 1);
         country.id = newId;
         db.countries.Add(country);
     }
     db.SaveChanges();
     return(RedirectToAction("CountryList"));
 }
 public ActionResult Edit([Bind(Include = "Name,Code,IsActive")] DropDownType dropDownType)
 {
     if (ModelState.IsValid)
     {
         if (!string.IsNullOrEmpty(Session["UserName"].ToString()))
         {
             dropDownType.ModifiedBy   = Session["UserName"].ToString();
             dropDownType.ModifiedDate = DateTime.Now;
         }
         db.Entry(dropDownType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dropDownType));
 }
Example #11
0
 public ActionResult Edit([Bind(Include = "DropDownTypeId,Name,Value,Description")] DropDownItem dropDownItem)
 {
     if (ModelState.IsValid)
     {
         if (!string.IsNullOrEmpty(Session["UserName"].ToString()))
         {
             dropDownItem.ModifiedBy   = Convert.ToInt64(Session["Id"].ToString());
             dropDownItem.ModifiedDate = DateTime.Now;
         }
         db.Entry(dropDownItem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DropDownTypeId = new SelectList(db.DropDownTypes, "DropDownTypeId", "Name", dropDownItem.DropDownTypeId);
     return(View(dropDownItem));
 }
Example #12
0
 public ActionResult Edit(Menu Menu)
 {
     if (Menu != null)
     {
         Menu oldMenu = db.Menus.FirstOrDefault(x => x.MenuId == Menu.MenuId);
         if (oldMenu == null)
         {
             throw new Exception("Menu not found");
         }
         oldMenu.OrderNo         = Menu.OrderNo;
         oldMenu.CompanyId       = Menu.CompanyId;
         oldMenu.Name            = Menu.Name;
         oldMenu.ModifiedBy      = System.Web.HttpContext.Current.User.Identity.Name;
         oldMenu.ModifiedDate    = DateTime.Now;
         oldMenu.IsActive        = Menu.IsActive;
         db.Entry(oldMenu).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", Menu.CompanyId);
     return(View(Menu));
 }
Example #13
0
 public ActionResult Edit(SubMenu subMenu)
 {
     if (subMenu != null)
     {
         SubMenu oldSubMenu = db.SubMenus.FirstOrDefault(x => x.SubMenuId == subMenu.SubMenuId);
         if (oldSubMenu == null)
         {
             throw new Exception("Sub Menu not found");
         }
         oldSubMenu.OrderNo         = subMenu.OrderNo;
         oldSubMenu.MenuId          = subMenu.MenuId;
         oldSubMenu.Name            = subMenu.Name;
         oldSubMenu.Controller      = subMenu.Controller;
         oldSubMenu.Param           = subMenu.Param;
         oldSubMenu.Action          = subMenu.Action;
         oldSubMenu.ModifiedBy      = System.Web.HttpContext.Current.User.Identity.Name;
         oldSubMenu.ModifiedDate    = DateTime.Now;
         oldSubMenu.IsActive        = subMenu.IsActive;
         db.Entry(oldSubMenu).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(subMenu));
 }