// GET: User/Edit/5 public ActionResult Edit(int id) { if (CurrentUser != null) { ViewData["SessionEnded"] = false; var User = UserService.FindUserByID(id); vw_UserDataModel userModel = null; UserPersonViewModel personData = null; if (User != null) { userModel = GetUserModel(User); if (User.PersonID.HasValue) { Base.Views.vw_PersonData person = PersonService.GetPerson(User.PersonID.Value); personData = new UserPersonViewModel { CBirthDate = person.BirthDate, Job = person.Job, Name = person.Name, NationalityID = person.NationalityID, NatNo = person.NatNo, PassportNo = person.PassportNo, PhoneNo = User.PhoneNo, address_address = person.address.address, address_CityID = person.address.CityID, address_PoliceStationID = person.address.PoliceStationID, ID = person.ID, BirthDateT = person.BirthDate, }; } } string[] li = Regex.Split(personData.address_address.ToString(), "/"); if (li[0] != null) { personData.address_address = li[0]; } if (li[1] != null) { personData.address_CityID = int.Parse(li[1]); } if (li[2] != null) { personData.address_PoliceStationID = int.Parse(li[2]); } personData.Age = CalculateAge(personData.BirthDateT.Value); return(PartialView(GetUserViewModel(userModel, personData))); } else { ViewData["SessionEnded"] = true; return(PartialView()); } }
internal static vw_PersonData Map(Base.Views.vw_PersonData caseParty) { return(new vw_PersonData { address_address = caseParty.address.address, address_CityID = caseParty.address.CityID, address_PoliceStationID = caseParty.address.PoliceStationID, //CBirthDate = caseParty.BirthDate.Value.Date, ID = caseParty.ID, Job = caseParty.Job, Name = caseParty.Name, NatNo = caseParty.NatNo, PassportNo = caseParty.PassportNo, PhoneNo = caseParty.PhoneNo, BirthDate = (caseParty.BirthDate.HasValue) ? caseParty.BirthDate.Value.ToShortDateString() : "", Age = caseParty.Age }); }
public JsonResult GetPersonData(string NatID) { RetrievedPersonData P = new RetrievedPersonData(); Base.Views.vw_PersonData PD = PersonService.GetPersons(NatID).FirstOrDefault(); if (PD != null) { P.ID = PD.ID; P.Name = PD.Name; P.NatNo = PD.NatNo; P.Job = PD.Job; P.BirthDate = PD.BirthDate.Value.ToShortDateString(); P.NationalityID = PD.NationalityID; P.PassportNo = PD.PassportNo; P.CityID = PD.address.CityID; P.Address = PD.address.address; P.PoliceStationID = PD.address.PoliceStationID; string[] li = Regex.Split(PD.address.address.ToString(), "/"); if (li[0] != null) { P.Address = li[0]; } if (li[1] != null) { P.CityID = int.Parse(li[1]); } if (li[2] != null) { P.PoliceStationID = int.Parse(li[2]); } //P.address = (PD.address_address != null ? new Base.Views.vw_Address { address = PD.address_address; CityID = PD.address_CityID; PoliceStationID = PD.address_PoliceStationID } : null); P.CleanFullName = Base.Utilities.RemoveSpaces(Base.Utilities.RemoveSpecialCharacters(PD.Name)); } return(Json(P, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(int CaseID, [Bind(Prefix = "PersonData")] Models.vw_PersonData PersonData, [Bind(Prefix = "Edit.CasePartyViewModels")] CasePartyViewModels CasePartyViewModels) { if (!CasePartyViewModels.OriginalPartyType.HasValue) { ModelState.AddModelError("OriginalPartyType", JIC.Base.Resources.Messages.RequiredErrorMessage); } if (!ModelState.IsValid) { return(CPartialView(PrepareCasePartiesViewModel(CaseID, PersonData, CasePartyViewModels))); } if (CasePartyViewModels.PartyType != CasePartyViewModels.OriginalPartyType) { using (var Transaction = this.DataContext.Database.BeginTransaction()) { var PartyData = PartiesService.GetCaseDefect(CaseID, CasePartyViewModels.id, CasePartyViewModels.OriginalPartyType); var DeleteStatus = PartiesService.DeleteCaseDefect(CaseID, CasePartyViewModels.id, CasePartyViewModels.OriginalPartyType); vw_CaseDefectData defect = new vw_CaseDefectData() { CaseID = CaseID, ID = CasePartyViewModels.id, IsCivilRightProsecutor = CasePartyViewModels.IsCivilRightProsecutor, //NationalID = this.NationalID, Order = CasePartyViewModels.PartiesOrder, //Name = PartyName, DefectType = CasePartyViewModels.PartyType, Crimes = CasePartyViewModels.CrimeTypes, DefendantStatus = CasePartyViewModels.DefendantStatus }; var AddStatus = PartiesService.AddCaseDefect(new vw_CaseDefectData { CaseID = CaseID, Crimes = CasePartyViewModels.CrimeTypes, DefectType = CasePartyViewModels.PartyType, IsCivilRightProsecutor = CasePartyViewModels.IsCivilRightProsecutor, PersonID = PartyData.PersonID, DefendantStatus = CasePartyViewModels.DefendantStatus ?? 0, }); //var AddStatus = PartiesService.AddCaseDefect(defect); if (DeleteStatus == DeleteDefectStatus.Deleted && AddStatus == SaveDefectsStatus.Saved) { Transaction.Commit(); } ViewBag.SavedEdite = true; return(CPartialView(PrepareCasePartiesViewModel(CaseID, PersonData, CasePartyViewModels)).WithErrorMessages(JIC.Base.Resources.Messages.OperationNotCompleted)); } } else { using (var Transaction = this.DataContext.Database.BeginTransaction()) { //Get PartyOriginalData var CasePartyData = PartiesService.GetCaseDefect(CaseID, CasePartyViewModels.id, CasePartyViewModels.PartyType); //UpdatePersonData Base.Views.vw_PersonData personData = PersonData.ToPersonData(); personData.ID = CasePartyData.PersonID; var PersonStatus = PersonService.EditPerson(personData); //Update Case Parties Data var CaseDefect = CasePartyViewModels.ToCaseDefectView(); CaseDefect.CaseID = CaseID; CaseDefect.PersonID = personData.ID; var DefectStatus = PartiesService.EditCaseDefect(CaseDefect); //If Party Exist in both Defendant and Victim we Needs to Update the Other As well var PersonParties = PartiesService.GetDefectsByCaseID(CaseID).Where(party => party.PersonID == CasePartyData.PersonID && party.DefectType != CasePartyViewModels.PartyType).ToList(); foreach (var party in PersonParties) { PartiesService.EditCaseDefect(new vw_CaseDefectData { CaseID = party.CaseID, Crimes = party.Crimes.Select(crime => crime.ID).ToList(), DefectType = party.DefectType, DefendantStatus = party.Status, IsCivilRightProsecutor = party.IsCivilRightProsecutor, Order = party.Order, PersonID = personData.ID, ID = party.ID }); } if (PersonStatus == PersonStatus.SuccefullSave && DefectStatus == SaveDefectsStatus.Saved) { Transaction.Commit(); ViewBag.SavedEdite = true; return(CPartialView(PrepareCasePartiesViewModel(CaseID, PersonData, CasePartyViewModels)).WithSuccessMessages(JIC.Base.Resources.Messages.OperationCompletedSuccessfully)); } else { return(CPartialView(PrepareCasePartiesViewModel(CaseID, PersonData, CasePartyViewModels)).WithErrorMessages(JIC.Base.Resources.Messages.OperationNotCompleted)); } } } // JavaScript("$(document).trigger('Parties:UpdateSuccefull');"); }
public ActionResult Create(WitnessViewModel WitnessModel, HttpPostedFileBase file) { if (CurrentUser != null) { ViewData["SessionEnded"] = false; try { if (ModelState.IsValid) { // int WitnessID; Base.Views.vw_PersonData vw_Witness = new Base.Views.vw_PersonData() { ID = WitnessModel.PersonID, Name = WitnessModel.Name, NatNo = WitnessModel.NatNo, Job = WitnessModel.Job, BirthDate = WitnessModel.GetBirthDate(), NationalityID = WitnessModel.NationalityID, PassportNo = WitnessModel.PassportNo, address = (WitnessModel.address_address != null ? new Base.Views.vw_Address { address = WitnessModel.address_address, CityID = WitnessModel.address_CityID, PoliceStationID = WitnessModel.address_PoliceStationID } : null), CleanFullName = Base.Utilities.RemoveSpaces(Base.Utilities.RemoveSpecialCharacters(WitnessModel.Name)), }; byte[] FileData = null; if (file != null && file.ContentLength > 0) { FileData = null; using (var binaryReader = new BinaryReader(file.InputStream)) { FileData = binaryReader.ReadBytes(file.ContentLength); } } // = new BinaryReader(WitnessModel.filePath.InputStream);//System.IO.File.ReadAllBytes(WitnessModel.filePath.); var ResultAddWitness = WitnessService.AddNewWitness(vw_Witness, (int)WitnessModel.ID, 0, FileData, CurrentUser.ID, (SystemUserTypes)CurrentUser.UserTypeID); if (ResultAddWitness == AddWitnessStatus.AddedSuccessfully) { //, "User", new { returnUrl = "/" } return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithSuccessMessages(JIC.Base.Resources.Messages.OperationCompletedSuccessfully)); } else if (ResultAddWitness == AddWitnessStatus.FailedToAdd) { return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithErrorMessages(JIC.Base.Resources.Messages.OperationNotCompleted)); } else if (ResultAddWitness == AddWitnessStatus.SavedBefore) { return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithErrorMessages(JIC.Base.Resources.Messages.WitnessSavedBefore)); } else if (ResultAddWitness == AddWitnessStatus.IsDefendant) { return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithErrorMessages(JIC.Base.Resources.Messages.PartyAlreadyExists)); } else if (ResultAddWitness == AddWitnessStatus.IsVictim) { return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithErrorMessages(JIC.Base.Resources.Messages.PartyAlreadyExists)); } else if (ResultAddWitness == AddWitnessStatus.IsLawyer) { return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithErrorMessages(JIC.Base.Resources.Messages.PersonIsALawyer)); } } // WitnessViewModel WitnessCreate = PersonViewModel(); return(RedirectTo(Url.Action("Index", "Witnesses", new { id = (int)WitnessModel.ID })).WithSuccessMessages(JIC.Base.Resources.Messages.OperationNotCompleted)); } catch (Exception ex) { return(ErrorPage(ex)); } } else { // return RedirectTo(Url.Action("login", "User", new { returnUrl = "/" })).WithErrorMessages("تم الخروج بشكل تلقائى لعدم التفاعل اكثر من 15 دقيقة"); ViewData["SessionEnded"] = true; return(CPartialView()); } }