public ModelResponse NewExperienceInformation(UserInfo user, ref ExperienceInformationVm vm, bool validateOnly) { try { //Authorization //Authorization if (user == null) { return(new ModelResponse(101)); } if (user != null) { if (!user.IsIndividual) { return(new ModelResponse(101)); } } //Validations // if (vm.graduationyear != null) return new ModelResponse(1); if (string.IsNullOrWhiteSpace(vm.JobTitle)) { return(new ModelResponse(1)); } if (string.IsNullOrWhiteSpace(vm.TypeofEmployment)) { return(new ModelResponse(1)); } if (string.IsNullOrWhiteSpace(vm.StartDate.ToShortDateString())) { return(new ModelResponse(1)); } if (vm.Name.IsNullOrWhiteSpace()) { return(new ModelResponse(1)); } if (vm.JobDescription.IsNullOrWhiteSpace()) { return(new ModelResponse(1)); } if (!validateOnly) { Repo.NewExperienceInformation(user, ref vm); } } catch (Exception ex) { return(new ModelResponse(ex)); } return(new ModelResponse(0, vm.IndividualExperienceID)); }
public long NewExperienceInformation(UserInfo user, ref ExperienceInformationVm vm) { using (var db = new LMISEntities()) using (var transaction = db.Database.BeginTransaction()) { try { var id = vm.IndividualExperienceID; if (id > 0) //Update { var tr = db.IndividualExperienceDetails .Where(r => r.IsDeleted == null && r.IndividualExperienceID == id) .ToList().Single(); tr.EmploymentStartDate = vm.StartDate; tr.EmploymentEndDate = vm.EndDate; tr.EmploymentJobTitle = vm.JobTitle; tr.TypeOfEmployment = vm.TypeofEmployment; tr.CurrentEmploymentStatus = vm.CurrentEmploymentStatus; tr.UpdateUserID = user.UserId; tr.UpdateDate = DateTime.Now; tr.ExpYears = (vm.EndDate.HasValue) ? Math.Abs(vm.EndDate.Value.Year - vm.StartDate.Year) : Math.Abs(DateTime.Now.Year - vm.StartDate.Year); tr.ExpMonths = (vm.EndDate.HasValue) ? Math.Abs(vm.EndDate.Value.Month - vm.StartDate.Month) : Math.Abs(DateTime.Now.Month - vm.StartDate.Month); // tr.ExpYears = (!vm.EndDate.HasValue) ? ((DateTime.Now.Year - vm.StartDate.Year) > 0) ? (DateTime.Now.Year - vm.StartDate.Year) : 0 : ((vm.EndDate.Value.Year - vm.StartDate.Year) > 0) ? (vm.EndDate.Value.Year - vm.StartDate.Year) : 0; // tr.ExpMonths = (!vm.EndDate.HasValue) ? ((DateTime.Now.Month - vm.StartDate.Month) > 0) ? (DateTime.Now.Month - vm.StartDate.Month) : 0 : ((vm.EndDate.Value.Month - vm.StartDate.Month) > 0) ? (vm.EndDate.Value.Month - vm.StartDate.Month) : 0; //Delete detail records var dr = db.IndividualExperienceDetails_Det .Where(r => r.IndividualExperienceID == id) .ToList(); db.IndividualExperienceDetails_Det.RemoveRange(dr); } else //Insert { var tr = new IndividualExperienceDetail { PortalUsersID = user.PortalUserId, EmploymentStartDate = vm.StartDate, EmploymentEndDate = vm.EndDate, EmploymentJobTitle = vm.JobTitle, TypeOfEmployment = vm.TypeofEmployment, CurrentEmploymentStatus = vm.CurrentEmploymentStatus, PostDate = DateTime.UtcNow, PostUserID = user.UserId, ExpYears = (vm.EndDate.HasValue) ? Math.Abs(vm.EndDate.Value.Year - vm.StartDate.Year) : Math.Abs(DateTime.Now.Year - vm.StartDate.Year), ExpMonths = (vm.EndDate.HasValue) ? Math.Abs(vm.EndDate.Value.Month - vm.StartDate.Month) : Math.Abs(DateTime.Now.Month - vm.StartDate.Month) // tr.ExpYears = (!vm.EndDate.HasValue) ? ((DateTime.Now.Year - vm.StartDate.Year) > 0) ? (DateTime.Now.Year - vm.StartDate.Year) : 0 : ((vm.EndDate.Value.Year - vm.StartDate.Year) > 0) ? (vm.EndDate.Value.Year - vm.StartDate.Year) : 0; // tr.ExpMonths = (!vm.EndDate.HasValue) ? ((DateTime.Now.Month - vm.StartDate.Month) > 0) ? (DateTime.Now.Month - vm.StartDate.Month) : 0 : ((vm.EndDate.Value.Month - vm.StartDate.Month) > 0) ? (vm.EndDate.Value.Month - vm.StartDate.Month) : 0; //Delete detail records }; db.IndividualExperienceDetails.Add(tr); db.SaveChanges(); vm.IndividualExperienceID = (long)tr.IndividualExperienceID; } //Insert detail records var mdr = new IndividualExperienceDetails_Det(); var ds = Utils.MultilingualDataSet( new Dictionary <string, GlobalString> { { "c1", vm.Name }, { "c2", vm.JobDescription }, }); foreach (var r in ds) { db.IndividualExperienceDetails_Det.Add(new IndividualExperienceDetails_Det() { IndividualExperienceID = vm.IndividualExperienceID, LanguageID = r["c1"].L, EmployerName = r["c1"].T, EmploymentJobDescription = r["c2"].T }); } db.SaveChanges(); transaction.Commit(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:"); } throw; } catch (Exception ex) { transaction.Rollback(); ExceptionDispatchInfo.Capture(ex).Throw(); } } return(vm.IndividualExperienceID); }
public static object PostNewExperienceInformation(ExperienceInformationVm data, bool validateOnly) { var mr = Mgr.NewExperienceInformation(Utils.LoggedUser, ref data, validateOnly); return(Utils.ServiceResponse(PageCode, mr)); }