public ActionResult Create(AttendenceViewModel viewModel) { if (ModelState.IsValid) { try { Attendence attendence = Mapper.Map <Attendence>(viewModel); attendence.Id = Guid.NewGuid(); attendence.CompanyId = CompanyCookie.CompId; _dbContext.Attendences.Add(attendence); _dbContext.SaveChanges(); Salary salary = new Salary(); salary.CompanyId = CompanyCookie.CompId; salary.Date = viewModel.Date; _dbContext.Salary.Add(salary); _dbContext.SaveChanges(); TempData["MessageToClientSuccess"] = "Attendence Date SuccessFully Created"; } catch (Exception ex) { // Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, ex); var msg = new ModelStateException(ex); TempData["MessageToClientError"] = msg; } return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(_dbContext.Companyies, "Id", "CompanyName"); return(View(viewModel)); }
public ActionResult Edit(MembershipViewModel viewModel) { if (ModelState.IsValid) { try { Membership membership = Mapper.Map <Membership>(viewModel); membership.CompanyId = CompanyCookie.CompId; _dbContext.Entry(membership).State = EntityState.Modified; _dbContext.SaveChanges(); TempData["MessageToClientSuccess"] = "SuccessFully Saved"; return(RedirectToAction("Index")); } catch (Exception ex) { var msg = new ModelStateException(ex); TempData["MessageToClientError"] = msg; return(View(viewModel)); } } // ViewBag.CompanyId = new SelectList(_dbContext.Companyies, "Id", "CompanyName", membership.CompanyId); viewModel.getAllDaysList = viewModel.getAllWeekDaysList(); return(View(viewModel)); }
public ActionResult Create(DepartmentViewModel viewModel) { if (!ModelState.IsValid) { throw new ModelStateException(ModelState); } if (ModelState.IsValid) { try { departmentBll.SaveDepartment(viewModel); return(RedirectToAction("Index")); } catch (DbUpdateException dbex) { // var error = new ModelStateException(dbex); Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, dbex); var msg = new ModelStateException(dbex); TempData["MessageToClient"] = msg; } catch (Exception ex) { Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, ex); var msg = new ModelStateException(ex); TempData["MessageToClient"] = msg; } } ViewBag.CompanyId = new SelectList(_dbContext.Companyies, "Id", "CompanyName", viewModel.CompanyId); ViewBag.BranchId = new SelectList(_dbContext.Branches, "Id", "Name"); return(View(viewModel)); }
public override async Task OnExceptionAsync(ExceptionContext context) { if (context.Exception is ModelStateException) { ModelStateException exception = (ModelStateException)context.Exception; context.ModelState.AddModelError(exception.Key, exception.Message); context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; } }
public ServiceException(ModelStateException modelState) { StatusCode = HttpStatusCode.InternalServerError; Error = CommunicationErrors.InvalidModel; Error.Details = modelState.Details.Select(t => new ODataErrorDetail { Message = t.Message, Target = t.Target }).ToList(); }
public UserViewModel PasswordChange(string username, string oldPassword, string newPassword) { Response <UserDto> response = EntityFactory.UserManager.PasswordChange(username, oldPassword, newPassword); if (response.HasErrors) { ModelStateException modelStateException = new ModelStateException(); response.ErrorMessages.ToList().ForEach(item => modelStateException.ModelErrors.Add(new ModelStateError() { FieldName = item.FieldName, Message = item.Message })); throw modelStateException; } return(response.Model.MapFromDto()); }
public ActionResult DeleteConfirmed(Guid id) { try { Membership membership = _dbContext.Memberships.Find(id); _dbContext.Memberships.Remove(membership); _dbContext.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { // Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, ex); var msg = new ModelStateException(ex); TempData["MessageToClientError"] = msg; } return(RedirectToAction("Delete")); }
public UserViewModel RegisterUser(RegisterUserViewModel model) { UserDto user = new UserDto(); user.MapToDto(model); Response <UserDto> response = EntityFactory.UserManager.SaveUser(user, CrudStatus.CREATE); if (response.HasErrors) { ModelStateException modelStateException = new ModelStateException(); response.ErrorMessages.ToList().ForEach(item => modelStateException.ModelErrors.Add(new ModelStateError() { FieldName = item.FieldName, Message = item.Message })); throw modelStateException; } return(response.Model.MapFromDto()); }
public PolicyViewModel CreateAd(CreateAdViewModel model) { PolicyDto policy = new PolicyDto(); policy.MapToDto(model); Response <PolicyDto> response = EntityFactory.PolicyManager.SavePolicy(policy, CrudStatus.CREATE); if (response.HasErrors) { ModelStateException modelStateException = new ModelStateException(); response.ErrorMessages.ToList().ForEach(item => modelStateException.ModelErrors.Add(new ModelStateError() { FieldName = item.FieldName, Message = item.Message })); throw modelStateException; } return(response.Model.MapFromDto()); }
public void OnActionExecuting(ActionExecutingContext context) { var logger = GetLogger(context.HttpContext.RequestServices); logger.LogInformation("{0} executing.", nameof(HandleModelStateErrorAttribute)); if (context.ModelState.IsValid) { return; } var modelStateError = new ModelStateException(context.ModelState); logger.LogError(modelStateError, "Validation errors occurred."); if (_throwModelStateException) { throw modelStateError; } context.Result = new BadRequestObjectResult(context.ModelState); }
public PolicyViewModel SavePolicy(PolicyViewModel model) { PolicyDto policy = new PolicyDto(); CrudStatus crudStatus = CrudStatusMapper.MapToEnum(model.CrudOperation); policy.MapToDto(model); Response <PolicyDto> response = EntityFactory.PolicyManager.SavePolicy(policy, crudStatus); if (response.HasErrors) { ModelStateException modelStateException = new ModelStateException(); response.ErrorMessages.ToList().ForEach(item => modelStateException.ModelErrors.Add(new ModelStateError() { FieldName = item.FieldName, Message = item.Message })); throw modelStateException; } return(model.CrudOperation == CrudOperation.DELETE ? new PolicyViewModel() : response.Model.MapFromDto()); }
public ActionResult Edit(string data, Guid dailyid, string HeadName, decimal Invoice, DateTime Date, Guid ContactId, Guid ParticularId, Guid?MembershipId, decimal Total) { if (ModelState.IsValid) { try { Daily daily = _dbContext.Daily.Find(dailyid); daily.HeadName = HeadName; daily.Invoice = Invoice; daily.Date = Date; daily.ContactId = ContactId; daily.ParticularId = ParticularId; // daily.Net = Net; daily.MembershipId = MembershipId; daily.DailyTotal = Total; if (HeadName == "Service") { daily.Debit = Total; daily.Credit = 0; //if (Net != null) //{ // daily.Debit = Total; // daily.Net = 0 - daily.Debit + Net; //} //else //{ // daily.Net = 0 - daily.Debit; //} } if (HeadName == "Sales") { daily.Debit = Total; daily.Credit = 0; //if (Net != null) //{ // daily.Debit = Total; // daily.Net = 0 - daily.Debit + Net; //} //else //{ // daily.Net = 0 - daily.Debit; //} } if (HeadName == "Expense") { daily.Debit = Total; daily.Credit = 0; //if (Net != null) //{ // daily.Debit = Total; // daily.Net = 0 - daily.Debit + Net; //} //else //{ // daily.Net = 0 - daily.Debit; //} } if (HeadName == "Revenue") { daily.Credit = Total; daily.Debit = 0; //if (Net != null) //{ // daily.Net = Net + daily.Credit; //} //else //{ // daily.Net = daily.Credit - 0; //} } var dailyItems = _dbContext.DailyItem.Where(i => i.DailyId == dailyid).ToList(); foreach (var item in dailyItems) { _dbContext.DailyItem.Remove(item); _dbContext.SaveChanges(); } SaveDailyItems(dailyid, data); _dbContext.Entry(daily).State = EntityState.Modified; _dbContext.SaveChanges(); return(Json(new { success = true })); } catch (Exception ex) { var msg = new ModelStateException(ex); return(Json(new { success = false, message = msg.Message })); //ModelState.AddModelError("", msg); //TempData["MessageToClientError"] = msg; } } return(View()); }
public ActionResult Create(string data, string HeadName, decimal Invoice, DateTime Date, Guid ContactId, Guid ParticularId, Guid?MembershipId, decimal Total) { if (ModelState.IsValid) { try { Daily daily = new Daily(); Guid dailyId = Guid.NewGuid(); daily.HeadName = HeadName; daily.Id = dailyId; daily.Invoice = Invoice; daily.Date = Date; daily.ContactId = ContactId; daily.ParticularId = ParticularId; daily.MembershipId = MembershipId; daily.DailyTotal = Total; if (HeadName == "Service") { daily.Debit = Total; daily.Credit = 0; //if (Net != null) //{ // daily.Debit = Total; // daily.Net = 0 - daily.Debit + Net; //} //else //{ // daily.Net = 0 - daily.Debit; //} } if (HeadName == "Sales") { daily.Debit = Total; daily.Credit = 0; //if (Net != null) //{ // daily.Debit = Total; // daily.Net = 0 - daily.Debit + Net; //} //else //{ // daily.Net = 0 - daily.Debit; //} } if (HeadName == "Expense") { daily.Debit = Total; daily.Credit = 0; //if (Net != null) //{ // daily.Debit = Total; // daily.Net = 0 - daily.Debit + Net; //} //else //{ // daily.Net = 0 - daily.Debit; //} } if (HeadName == "Revenue") { daily.Credit = Total; daily.Debit = 0; //if (Net != null) //{ // daily.Net = Net + daily.Credit; //} //else //{ // daily.Net = daily.Credit - 0; //} } SaveDailyItems(dailyId, data); _dbContext.Daily.Add(daily); _dbContext.SaveChanges(); return(Json(new { success = true })); } catch (Exception ex) { var msg = new ModelStateException(ex); return(Json(new { success = false, message = msg.Message })); //ModelState.AddModelError("", msg); //TempData["MessageToClientError"] = msg; } } return(View()); }
public ActionResult Save(string employeeName, string inTimeVal, string outTimeVal, Guid AttendenceId, string attendenceTypeVal, DateTime date, Guid empidval, string command) { string messageToClient = string.Empty; if (ModelState.IsValid) { try { if (command == "Submit") { int overTimeCalHr = 0; int th = 0; EmployeeAttendence employeeAttendence = new EmployeeAttendence(); EmployeeSalary employeeSalary = new EmployeeSalary(); EmployeeSalaryDetail retriveEmployeeSalaryDetail = _dbContext.EmployeeSalaryDetails.Where(es => es.ContactId == empidval).FirstOrDefault(); if (inTimeVal == "") { } else { DateTime i = Convert.ToDateTime(inTimeVal); if (outTimeVal == "") { } else { DateTime o = Convert.ToDateTime(outTimeVal); //hour calculation int inTime = i.Hour; int outTime = o.Hour; if (inTime == outTime) { inTime = 0; outTime = 0; } if (inTime > 12) { int newInTime = 24 - inTime; th = newInTime + outTime; } else { th = outTime - inTime; } if (retriveEmployeeSalaryDetail != null) { if (retriveEmployeeSalaryDetail.OverTimeCal != null) { DateTime overtimeCal = Convert.ToDateTime(retriveEmployeeSalaryDetail.OverTimeCal); overTimeCalHr = overtimeCal.Hour; //work hour and overtime hour Cal // retriving overtime and subtracting frm total hr if (th > overTimeCalHr) { int otHrcal = th - overTimeCalHr; employeeAttendence.WorkHours = overTimeCalHr; employeeSalary.WorkHours = overTimeCalHr; employeeAttendence.OverTimeHours = otHrcal; employeeSalary.OverTimeHours = otHrcal; } else { employeeAttendence.WorkHours = th; employeeSalary.WorkHours = th; employeeAttendence.OverTimeHours = 0; employeeSalary.OverTimeHours = 0; } } } //total Hours Cal int im = i.Minute; int om = o.Minute; int t = im + om; if (im == om) { employeeAttendence.TotalTime = Convert.ToString(th); } else if (im > om) { employeeAttendence.TotalTime = Convert.ToString(th); } else if (t > 60) { int totalhour = th + 1; int min = t - 60; employeeAttendence.TotalTime = totalhour + " : " + min; } else { employeeAttendence.TotalTime = th + " : " + t; } } } employeeAttendence.AttendenceId = AttendenceId; employeeAttendence.EmployeeId = empidval; employeeAttendence.FullName = employeeName; employeeAttendence.AttendenceType = attendenceTypeVal; employeeAttendence.Date = date; employeeAttendence.InTime = inTimeVal; employeeAttendence.OutTime = outTimeVal; employeeAttendence.Status = true; _dbContext.EmployeeAttendences.Add(employeeAttendence); //emp salary Salary salary = _dbContext.Salary.Where(s => s.Date == date).FirstOrDefault(); employeeSalary.FullName = employeeName; employeeSalary.RatePerHour = retriveEmployeeSalaryDetail.RatePerHour; employeeSalary.RatePerHourOvertime = retriveEmployeeSalaryDetail.RatePerHourOvertime; employeeSalary.Date = date; employeeSalary.SalaryId = salary.Id; _dbContext.EmployeeSalaries.Add(employeeSalary); _dbContext.SaveChanges(); } else { int overTimeCalHr = 0; int th = 0; EmployeeAttendence employeeAttendence = _dbContext.EmployeeAttendences.Where(ea => ea.AttendenceId == AttendenceId && ea.FullName == employeeName).FirstOrDefault(); Salary salary = _dbContext.Salary.Where(s => s.Date == date).FirstOrDefault(); EmployeeSalary employeeSalary = _dbContext.EmployeeSalaries.Where(es => es.SalaryId == salary.Id && es.FullName == employeeName).FirstOrDefault(); if (inTimeVal == "") { } else { DateTime i = Convert.ToDateTime(inTimeVal); if (outTimeVal == "") { } else { DateTime o = Convert.ToDateTime(outTimeVal); //hour calculation int inTime = i.Hour; int outTime = o.Hour; if (inTime == outTime) { inTime = 0; outTime = 0; } if (inTime > 12) { int newInTime = 24 - inTime; th = newInTime + outTime; } else { th = outTime - inTime; } EmployeeSalaryDetail retriveEmployeeSalaryDetail = _dbContext.EmployeeSalaryDetails.Where(es => es.ContactId == empidval).FirstOrDefault(); if (retriveEmployeeSalaryDetail != null) { if (retriveEmployeeSalaryDetail.OverTimeCal != null) { DateTime overtimeCal = Convert.ToDateTime(retriveEmployeeSalaryDetail.OverTimeCal); overTimeCalHr = overtimeCal.Hour; //work hour and overtime hour Cal // retriving overtime and subtracting frm total hr if (th > overTimeCalHr) { int otHrcal = th - overTimeCalHr; employeeAttendence.WorkHours = overTimeCalHr; employeeSalary.WorkHours = overTimeCalHr; employeeAttendence.OverTimeHours = otHrcal; employeeSalary.OverTimeHours = otHrcal; } else { employeeAttendence.WorkHours = th; employeeSalary.WorkHours = th; employeeAttendence.OverTimeHours = 0; employeeSalary.OverTimeHours = 0; } } } //total Hours Cal int im = i.Minute; int om = o.Minute; int t = im + om; if (im == om) { employeeAttendence.TotalTime = Convert.ToString(th); } else if (im > om) { employeeAttendence.TotalTime = Convert.ToString(th); } else if (t > 60) { int totalhour = th + 1; int min = t - 60; employeeAttendence.TotalTime = totalhour + " : " + min; } else { employeeAttendence.TotalTime = th + " : " + t; } //emp salary employeeSalary.FullName = employeeName; employeeSalary.RatePerHour = retriveEmployeeSalaryDetail.RatePerHour; employeeSalary.RatePerHourOvertime = retriveEmployeeSalaryDetail.RatePerHourOvertime; employeeSalary.Date = date; employeeSalary.SalaryId = salary.Id; _dbContext.Entry(employeeSalary).State = EntityState.Modified; _dbContext.SaveChanges(); } } employeeAttendence.AttendenceId = AttendenceId; employeeAttendence.EmployeeId = empidval; employeeAttendence.FullName = employeeName; employeeAttendence.AttendenceType = attendenceTypeVal; employeeAttendence.InTime = inTimeVal; employeeAttendence.OutTime = outTimeVal; employeeAttendence.Status = true; _dbContext.Entry(employeeAttendence).State = EntityState.Modified; } _dbContext.SaveChanges(); return(Json(new { success = true })); } catch (DbUpdateException dbex) { // var error = new ModelStateException(dbex); // Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, dbex); var msg = new ModelStateException(dbex); TempData["MessageToClient"] = msg; messageToClient = msg.ToString(); } catch (Exception ex) { // Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, ex); var msg = new ModelStateException(ex); TempData["MessageToClient"] = msg; } } ViewBag.CompanyId = new SelectList(_dbContext.Companyies, "Id", "CompanyName"); return(View()); }
public ActionResult Create(CustomerViewModel viewModel) { if (ModelState.IsValid) { try { // Product product = Mapper.Map<Product>(viewModel); Contact customer = Mapper.Map <Contact>(viewModel); customer.Id = Guid.NewGuid(); if (viewModel.MainImageNameFile != null) { string fName = ""; HttpPostedFileBase file = viewModel.MainImageNameFile; fName = viewModel.MainImageNameFile.FileName; string ImageNameWithOutExtention = System.IO.Path.GetFileNameWithoutExtension(fName); string extension = Path.GetExtension(fName); var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Customers", Server.MapPath(@"\"))); string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath"); var fileName1 = Path.GetFileName(file.FileName); bool isExists = System.IO.Directory.Exists(pathString); if (!isExists) { System.IO.Directory.CreateDirectory(pathString); } var path = string.Format("{0}\\{1}", pathString, file.FileName); file.SaveAs(path); var versions = new Dictionary <string, string>(); var imagePath = string.Format("{0}\\{1}", pathString, ImageNameWithOutExtention); versions.Add("_small", "maxwidth=100&maxheight=100&format=jpg"); versions.Add("_medium", "maxwidth=500&maxheight=500&format=jpg"); versions.Add("_large", "maxwidth=900&maxheight=900&format=jpg"); foreach (var suffix in versions.Keys) { file.InputStream.Seek(0, SeekOrigin.Begin); ImageBuilder.Current.Build( new ImageJob( file.InputStream, imagePath + suffix, new Instructions(versions[suffix]), false, true)); } customer.MainImageName = ImageNameWithOutExtention; customer.ImageExtention = extension; } customer.Type = "Customer"; if (viewModel.OpeningBalance == null) { customer.OpeningBalance = 0; } customer.OpeningBalance = viewModel.OpeningBalance; // customer.CompanyId = CompanyCookie.CompId; _dbContext.Contacts.Add(customer); _dbContext.SaveChanges(); TempData["MessageToClientSuccess"] = "SuccessFully Saved"; return(RedirectToAction("Index")); } catch (DbUpdateException dbex) { // var error = new ModelStateException(dbex); // Log4NetHelper.Log(String.Format("Cannot Create Deparment {0} ", viewModel.Id), LogLevel.ERROR, "Department", viewModel.Id, User.Identity.Name, dbex); var msg = new ModelStateException(dbex); TempData["MessageToClientError"] = msg; } catch (Exception ex) { ModelState.AddModelError("", ex.Message); ViewBag.MembershipId = new SelectList(_dbContext.Memberships, "Id", "MembershipName"); viewModel.getAllGenderList = viewModel.getGenderList(); viewModel.getAllCustomerTypeList = viewModel.getCustomerTypeList(); return(View(viewModel)); } } viewModel.getAllGenderList = viewModel.getGenderList(); viewModel.getAllCustomerTypeList = viewModel.getCustomerTypeList(); // ViewBag.MembershipId = new SelectList(_dbContext.Memberships, "Id", "MembershipName", customer.MembershipId); return(View(viewModel)); }