public IHttpActionResult PutDeparatments(long id, Deparatments deparatments) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != deparatments.DepartmentID) { return(BadRequest()); } db.Entry(deparatments).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DeparatmentsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutEmployees(long id, Employees employees) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employees.EmployeeID) { return(BadRequest()); } db.Entry(employees).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeesExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Post(Employee model) { if (ModelState.IsValid) { Db.Employee.Add(model); Db.SaveChanges(); return(Ok(model)); } return(Content(HttpStatusCode.BadRequest, "failed to save emp")); }
public IHttpActionResult Post(Department model) { if (!ModelState.IsValid) { return(BadRequest("Invalid")); } Db.Depertment.Add(model); Db.SaveChanges(); return(Ok(model)); }
public IHttpActionResult Post(Product model) { if (model != null) { Db.Products.Add(model); Db.SaveChanges(); return(Ok(model)); } return(Content(HttpStatusCode.BadRequest, "failed to save emp")); }
public IHttpActionResult Post(Category model) { if (!ModelState.IsValid) { return(BadRequest("Invalid")); } Db.categories.Add(model); Db.SaveChanges(); return(Ok(model)); }
public ActionResult Create([Bind(Include = "Id,Name")] Country country) { if (ModelState.IsValid) { db.Countries.Add(country); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(country)); }
public ActionResult Create([Bind(Include = "Id,Name,StateId")] City city) { if (ModelState.IsValid) { db.Cities.Add(city); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StateId = new SelectList(db.States, "Id", "Name", city.StateId); return(View(city)); }
public ActionResult Create([Bind(Include = "Id,Name,CountryId")] State state) { if (ModelState.IsValid) { db.States.Add(state); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CountryId = new SelectList(db.Countries, "Id", "Name", state.CountryId); return(View(state)); }
public ActionResult Create(Employee employee) { try { dbContext.Employees.Add(employee); dbContext.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Cliente emp) { try { // TODO: Add insert logic here db.clientes.Add(emp); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult AddEditTechnology(Technologies technologies) { if (Session["EmpName"] != null) { if (ModelState.IsValid) { try { using (EmpDbContext Techdb = new EmpDbContext()) { if (technologies.TechId > 0) { //update Technologies techlist = Techdb.Technologies.SingleOrDefault(x => x.TechId == technologies.TechId); techlist.Technology = technologies.Technology; techlist.Description = technologies.Description; Techdb.SaveChanges(); } else { //Insert //Technologies techins = new Technologies(); //techins.Technology = technologies.Technology; //techins.Description = technologies.Description; technologies.Checkstatus = "Y"; Techdb.Technologies.Add(technologies); Techdb.SaveChanges(); } } ModelState.Clear(); return(RedirectToAction("Index", technologies)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Technology", "Index"))); } } return(RedirectToAction("AddEditTechnology", technologies.TechId)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Create(Employee employee) { try { //employee.ID = EmpList.Count + 1; //EmpList.Add(employee); db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult DeleteSiteSettings(int SiteID) { // SiteSettings model = new SiteSettings(); using (EmpDbContext db = new EmpDbContext()) { SiteSettings sitelist = db.siteSettings.SingleOrDefault(x => x.SettingsID == SiteID); sitelist.Checkstatus = "N"; db.SaveChanges(); } return(RedirectToAction("SiteSetting", "Utility")); }
public ActionResult AddEditRole(Role role) { if (Session["EmpName"] != null) { if (ModelState.IsValid) { try { using (EmpDbContext db = new EmpDbContext()) { if (role.Roleid > 0) { //update Role rolelist = db.Roles.SingleOrDefault(x => x.Roleid == role.Roleid); rolelist.RoleName = role.RoleName; db.SaveChanges(); } else { //Insert role.Checkstatus = "Y"; db.Roles.Add(role); db.SaveChanges(); } } ModelState.Clear(); return(RedirectToAction("Roles", "Utility")); } catch (Exception ex) { //return View("Error", new HandleErrorInfo(ex, "Utility", "Roles")); } } return(RedirectToAction("AddEditRole", role.Roleid)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult DeleteRole(int RoleID) { Role model = new Role(); using (EmpDbContext db = new EmpDbContext()) { Role rolelist = db.Roles.SingleOrDefault(x => x.Roleid == RoleID); rolelist.Checkstatus = "N"; db.SaveChanges(); } return(RedirectToAction("Roles", "Utility")); }
public ActionResult DeleteTech(int TechId) { Technologies model = new Technologies(); using (EmpDbContext Techdb = new EmpDbContext()) { Technologies techlist = Techdb.Technologies.SingleOrDefault(x => x.TechId == TechId); techlist.Checkstatus = "N"; Techdb.SaveChanges(); } return(RedirectToAction("Index", "Technology")); }
public ActionResult Register(User user) { if (ModelState.IsValid) { try { using (EmpDbContext db = new EmpDbContext()) { var chkUser = (from s in db.Users where s.UserName == user.UserName || s.Email == user.Email select s).FirstOrDefault(); if (chkUser == null) { var keyNew = Helper.GeneratePassword(10); var password = Helper.EncodePassword(user.Password, keyNew); user.Password = password; //user.Checkstatus = "Y"; user.Vcode = keyNew; db.Users.Add(user); db.SaveChanges(); ModelState.Clear(); ViewBag.Message = "Registration Successful"; //var emailpassword = "******"; //var sub = "Sample application Registration"; //var body = "You have been succesfully registered in Sample application"; //RegEmail(user.Email, sub, body, emailpassword); return(RedirectToAction("Index", "Home")); } var p = new User(); p.RoleList = db.Roles.ToList(); ViewBag.Message = "User Already Exists!"; return(View(p)); } } catch (Exception e) { logger.ErrorException("Error occured in registration", e); ViewBag.Message = "Some exception occured" + e; return(RedirectToAction("Register")); } } else { ViewBag.Message = "Registration Failed"; return(RedirectToAction("Register")); } }
public void ActivateSiteSetting(int SiteID) { using (EmpDbContext db = new EmpDbContext()) { SiteSettings Inactivate = db.siteSettings.Where(x => x.IsActive == true).FirstOrDefault(); if (Inactivate != null) { Inactivate.IsActive = false; } SiteSettings sitelist = db.siteSettings.SingleOrDefault(x => x.SettingsID == SiteID); sitelist.IsActive = true; db.SaveChanges(); } }
public ActionResult EmpDelete(int id) { if (Session["EmpName"] != null) { using (EmpDbContext empDb = new EmpDbContext()) { var result = (from s in empDb.Employees where s.EmployeeId == id select s).FirstOrDefault(); empDb.Employees.Remove(result); empDb.SaveChanges(); } return(RedirectToAction("Contact")); } else { return(RedirectToAction("Index")); } }
public ActionResult AddEmp(Employee employee) { if (Session["EmpName"] != null) { try { if (ModelState.IsValid) { using (EmpDbContext empDb = new EmpDbContext()) { using (DbContextTransaction transaction = empDb.Database.BeginTransaction()) { try { empDb.Employees.Add(employee); empDb.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); Console.WriteLine("Error occurred."); } } } ModelState.Clear(); return(RedirectToAction("Contact")); } return(View()); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "EmployeeInfo", "Create"))); } } else { return(RedirectToAction("Index")); } }
public ActionResult EditEmp(Employee employee) { if (Session["EmpName"] != null) { try { using (EmpDbContext empDb = new EmpDbContext()) { var data = (from a in empDb.Employees where a.EmployeeId == employee.EmployeeId select a).FirstOrDefault(); data.Company = employee.Company; data.CountryId = employee.CountryId; data.StateId = employee.StateId; data.Description = employee.Description; data.IsEmployeeRetired = employee.IsEmployeeRetired; data.Name = employee.Name; data.EmpDate = employee.EmpDate; data.IsActive = employee.IsActive; empDb.Entry(data).State = EntityState.Modified; empDb.SaveChanges(); } return(RedirectToAction("Contact")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "EmployeeInfo", "Create"))); } // return RedirectToAction("EditEmp"); } else { return(RedirectToAction("Index")); } }
public JsonResult Create(FileUpload img, HttpPostedFileBase ImageFile) { EmpDbContext db = new EmpDbContext(); int imageId = 0; var file = ImageFile; //byte[] imagebyte = null; if (file != null) { string filename = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath("/Assets/" + filename)); //BinaryReader reader = new BinaryReader(file.InputStream); Stream stream = file.InputStream; BinaryReader binaryReader = new BinaryReader(stream); Byte[] image = binaryReader.ReadBytes((int)stream.Length); //imagebyte = reader.ReadBytes(file.ContentLength); FileUpload fimg = new FileUpload { FileName = filename, Imagelength = image, ImagePath = "/Assets/" + filename, Checkstatus = "Y" }; db.FileUploads.Add(fimg); db.SaveChanges(); imageId = fimg.ImageId; } return(Json(imageId, JsonRequestBehavior.AllowGet)); }
public ActionResult MenuManagement(FormCollection collection) { if (Session["EmpName"] != null) { using (EmpDbContext db = new EmpDbContext()) { var menulist = db.MenuManagement.Where(x => x.Checkstatus == "Y").Select(p => p.Menu_NAME).ToList(); List <int> applist = new List <int>(); StringBuilder sb = new StringBuilder(); // sb.Append("0"); foreach (var item in menulist) { if (!string.IsNullOrEmpty(collection[item])) { var checkResp = collection[item].Split(',')[0]; if (checkResp != "false") { //sb.Append(", " + int.Parse(checkResp)); sb.Append(int.Parse(checkResp) + " ,"); } } } var rid = int.Parse(collection["hdnroleid"]); var menures = sb.ToString(); var result = (from s in db.Roles where s.Roleid == rid select s).FirstOrDefault(); result.Menu_display = menures.Remove(menures.Length - 1); db.SaveChanges(); } return(RedirectToAction("Roles")); } else { return(RedirectToAction("Index", "Home")); } }
public IHttpActionResult Post([FromBody] EmployeeViewModel e) { var emp = new Employee() { FirstName = e.FirstName, LastName = e.LastName, Address = e.Address, Zip = e.Zip, CountryId = e.CountryId, StateId = e.StateId, CityId = e.CityId }; emp.PayMaster.Add(new PayMaster() { Basic = e.Basic, HRA = e.HRA, DA = e.DA }); db.Employees.Add(emp); db.SaveChanges(); return(Ok()); }
public ActionResult AddEditSettings(SiteSettings model, HttpPostedFileBase imageFile) { try { var file = imageFile; using (EmpDbContext db = new EmpDbContext()) { //update if (model.SettingsID > 0) { if (ModelState.IsValid) { SiteSettings settingslist = db.siteSettings.SingleOrDefault(x => x.SettingsID == model.SettingsID); settingslist.SettingName = model.SettingName; settingslist.ApplicationTitle = model.ApplicationTitle; settingslist.ApplicationTitleColour = model.ApplicationTitleColour; settingslist.ApplicationTitleFont = model.ApplicationTitleFont; settingslist.ApplicationTitleSize = model.ApplicationTitleSize; settingslist.MenuColour = model.MenuColour; settingslist.MenuTextColour = model.MenuTextColour; settingslist.NavColour = model.NavColour; settingslist.NavTextColour = model.NavTextColour; if (file != null) { string filename = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath("/Assets/" + filename)); Stream stream = file.InputStream; BinaryReader binaryReader = new BinaryReader(stream); Byte[] image = binaryReader.ReadBytes((int)stream.Length); //imagebyte = reader.ReadBytes(file.ContentLength); settingslist.FileName = filename; settingslist.Imagelength = image; settingslist.ImagePath = "/Assets/" + filename; } db.SaveChanges(); ModelState.Clear(); } else { return(View()); } } //Insert else { if (file != null) { string filename = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath("/Assets/" + filename)); Stream stream = file.InputStream; BinaryReader binaryReader = new BinaryReader(stream); Byte[] image = binaryReader.ReadBytes((int)stream.Length); //imagebyte = reader.ReadBytes(file.ContentLength); model.FileName = filename; model.Imagelength = image; model.ImagePath = "/Assets/" + filename; } model.Checkstatus = "Y"; db.siteSettings.Add(model); db.SaveChanges(); } } return(RedirectToAction("SiteSetting")); } catch (Exception e) { logger.ErrorException("Error occured in Home controller Index Action", e); return(RedirectToAction("SiteSetting")); } }
public bool SaveChanges() { return(_context.SaveChanges() >= 0); }
public ActionResult Enter(EmpModel model) { db.Employees.Add(model); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }