public async Task <IActionResult> Delete(OfficeViewModel officeVM) { await _officeRepo.DeleteOffice(officeVM.Office); TempData["message"] = "Your data has been deleted successfully."; TempData["toasterType"] = ToasterType.success; //return RedirectToAction(nameof(Index)); return(Redirect(officeVM.ReturnUrl)); }
public ActionResult Edit(OfficeViewModel model) { ResponseResult result = OfficeRepo.Update(model); return(Json(new { success = result.Success, message = result.ErrorMessage, entity = result.Entity }, JsonRequestBehavior.AllowGet)); }
public void GetOfficeListCommand_SelectedOfficeIsSetToNullWhenExecuted() { var viewModel = new OfficeViewModel(_mock.Object) { SelectedOffice = new Office() }; viewModel.GetOfficeListCommand.Execute(null); Assert.IsNull(viewModel.SelectedOffice); }
public ActionResult Edit(OfficeViewModel office) { if (ModelState.IsValid) { office.LoggedOnUser = SessionVars.UserName; office.SaveViewModel(); TempData["Success"] = "Office updated successfully!"; return(RedirectToAction("Edit", new { controller = "Office", id = office.Id })); } return(View(office)); }
public async Task <IActionResult> Edit(int id, string returnUrl = null) { if (String.IsNullOrEmpty(returnUrl)) { returnUrl = Request.Headers["Referer"].ToString(); } var office = await _officeRepo.GetOffice(id); OfficeViewModel officeVM = OfficeViewModelFactory.Edit(office, returnUrl); return(View("Edit", officeVM)); }
// GET: Office/Detail public ActionResult Detail(int id) { OfficeViewModel vm = new OfficeViewModel(id) { LoggedOnUser = SessionVars.UserName }; if (vm.UserList.All(x => x.Username != vm.LoggedOnUser)) { return(RedirectToAction("AccessDenied", new { controller = "Error" })); } return(View(vm)); }
public static ResponseResult Delete(OfficeViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_office ofc = db.t_office.Where(o => o.id == entity.id).FirstOrDefault(); if (ofc != null) { ofc.is_delete = true; ofc.deleted_by = entity.UserId; ofc.deleted_on = DateTime.Now; db.SaveChanges(); object data = new { ofc.id, ofc.name, ofc.phone, ofc.address }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Modified"; log.json_insert = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Office Not Fount"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public MainWindowViewModel(ISystemUser systemUser, ISystem system, WorkTimeRecorderViewModel workTimeRecorderViewModel, WorkTimeSummaryViewModel workTimeSummaryViewModel, OfficeViewModel officeViewModel) { this.systemUser = systemUser; this.system = system; this.workTimeRecorderViewModel = workTimeRecorderViewModel; this.workTimeSummaryViewModel = workTimeSummaryViewModel; this.officeViewModel = officeViewModel; Pages = ConfigurePages(); CurrentPage = Pages[0]; CurrentPage.IsSelected = true; }
public async Task <ActionResult> Edit(OfficeViewModel office) { if (!ModelState.IsValid) { return(View(office)); } var editOffice = await _db.Offices.FindAsync(office.Id); editOffice.Name = office.Name; _db.Entry(editOffice).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public void AddCommand_CannotExecuteWhenCityIsNotValid() { var viewModel = new OfficeViewModel(_mock.Object) { SelectedOffice = new Office { StreetNumber = 124, StreetName = "rue Saint André", City = null, ZipCode = 59800 } }; Assert.IsFalse(viewModel.AddCommand.CanExecute(null)); }
public IActionResult Index() { var model = new OfficeViewModel { Cartriges = _context.Cartridges.Include(c => c.Printer).Include(c => c.Place).ThenInclude(pl => pl.City) .Where(c => c.PlaceId == currentPlace.Value.Id), Printers = _context.Printers.Include(p => p.Cartidge) .Include(p => p.Office).ThenInclude(pl => pl.City) .Where(p => p.OfficeId == currentPlace.Value.Id) }; ViewBag.CurrentPlace = currentPlace.Value; ViewData.Model = model; return(View()); }
public IActionResult Edit(OfficeViewModel model) { if (model.Id > 0) { var dbItem = _officesService.GetById(model.Id); if (ReferenceEquals(dbItem, null)) { return(NotFound()); } dbItem.Name = model.Name; dbItem.Address = model.Address; } return(RedirectToAction(nameof(Offices))); }
public ActionResult Create(OfficeViewModel ofc) { if (ModelState.IsValid) { Office newOffice = new Office(); string division = ofc.Division; int count = officeService.getRowCount() + 1; string offcieid = division[0].ToString() + division[1].ToString() + division[2].ToString() + "-" + ofc.Area + "-" + count; newOffice.OfficeId = offcieid; newOffice.Location = "House : " + ofc.House + ", Road : " + ofc.Road + ", " + ofc.Area + ", " + division; newOffice.OfficialNumber = ofc.OfficialNumber; officeService.Insert(newOffice); return(RedirectToAction("Index", "Office")); } return(View(ofc)); }
public IActionResult Add([FromBody] OfficeViewModel officeViewModel) { try { var officeModel = Models.ObjectMapper <OfficeViewModel, Office> .Map(officeViewModel); if (_officeService.CheckDuplicate(officeModel) > 0) { var errorMessage = "Duplicate value entered for either code or name !!"; ModelState.AddModelError("", errorMessage); return(BadRequest(ModelState)); } if (ModelState.IsValid) { Guid id = Guid.NewGuid(); officeModel.OfficeGuid = id; officeModel.CreatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); officeModel.CreatedBy = id; officeModel.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); officeModel.UpdatedBy = id; officeModel.IsActive = true; officeModel.IsDeleted = false; _officeService.Add(officeModel); //audit log.. var additionalInformation = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Added.ToString(), ResourceType.Office.ToString()); //var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Office/Details/" + officeModel.OfficeGuid); var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + "/admin/office"; var additionalInformationWithUri = string.Format("<a href=\"{0}\">{1}</a>", additionalInformationURl, additionalInformation); var resource = string.Format("{0} </br> GUID:{1} </br> Office Name:{2} </br> Office Code:{3}", ResourceType.Office.ToString(), officeModel.OfficeGuid, officeModel.OfficeName, officeModel.OfficeCode); AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), officeModel, resource, officeModel.OfficeGuid, UserHelper.GetHostedIp(HttpContext), "Office Added", Guid.Empty, "Successful", "", additionalInformationWithUri, additionalInformationURl); return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!", office = new { officeGuid = id, officeName = officeModel.OfficeName } })); } return(BadRequest(ModelState)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(BadRequestFormatter.BadRequest(this, e)); } }
public async Task <IActionResult> AddOffice(OfficeViewModel officeViewModel) { if (ModelState.IsValid) { var newOffice = new Office { Address = officeViewModel.Address, PhoneNumber = officeViewModel.PhoneNumber }; await _officeManager.AddOfficeAsync(newOffice); return(Redirect("/Offices/")); } //If we get this far - something wrong happened! return(this.View(officeViewModel)); }
public ActionResult Detail(Guid id) { OfficeViewModel officeViewModel = new OfficeViewModel(); try { var officeModel = _officeService.GetDetailById(id); officeViewModel = Models.ObjectMapper <Office, OfficeViewModel> .Map(officeModel); return(PartialView(officeViewModel)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(officeViewModel)); } }
public async Task <IActionResult> Update(OfficeViewModel officeViewModel) { var office = await _officeManager.GetOfficeAsync(officeViewModel.Id); if (office.Address != officeViewModel.Address) { office.Address = officeViewModel.Address; _officeManager.UpdateOffice(office); } if (office.PhoneNumber != officeViewModel.PhoneNumber) { office.PhoneNumber = officeViewModel.PhoneNumber; _officeManager.UpdateOffice(office); } return(this.Redirect("/Offices/")); }
public void PropertyChanged_IsRaisedForSelectedOfficeWhenSelectedOfficePropertyHasChanged() { var viewModel = new OfficeViewModel(_mock.Object); var eventRaised = false; viewModel.PropertyChanged += (sender, e) => { if (e.PropertyName == "SelectedOffice") { eventRaised = true; } }; viewModel.SelectedOffice = null; Assert.IsTrue(eventRaised); }
public ActionResult Edit(OfficeViewModel office) { if (!string.IsNullOrEmpty(office.ContactPhone)) { office.ContactPhone = Regex.Replace(office.ContactPhone, @"[^\d]", ""); //strip off any masking from the UI } if (ModelState.IsValid) { office.LoggedOnUser = SessionVars.UserName; office.SaveViewModel(); TempData["Success"] = "Office updated successfully!"; return(RedirectToAction("Edit", new { controller = "Office", id = office.Id })); } return(View(office)); }
public ActionResult Edit(int id) { Office ofc = _OfficeService.Get(id); OfficeViewModel model = new OfficeViewModel(); model.objoffice = ofc; model.Cntries = new SelectList(_CountryService.GetAll(), "Id", "Name", ofc.Country); model.Cties = new SelectList(_CityService.GetCitiesByCountry(Convert.ToInt32(ofc.Country)) .Select(x => new { x.Id, x.Name }), "Id", "Name", ofc.City); model.states = new SelectList(_CityService.Getstatebycity(Convert.ToInt32(ofc.City)) .Select(x => new { x.Id, x.Name }), "Id", "Name", ofc.State); model.CntrySelect = Convert.ToInt32(ofc.Country); model.CitySelect = Convert.ToInt32(ofc.City); model.StateSelect = Convert.ToInt32(ofc.State); return(View(model)); }
public IActionResult Create([FromBody] OfficeViewModel model) { model = new OfficeViewModel() { Id = Guid.NewGuid(), ParentId = Guid.NewGuid(), ParentIds = ",,", CreateBy = Guid.NewGuid(), CreateDate = DateTime.Now, DelFlag = 0, OfficeCode = null, OfficeName = "测试", OfficeType = 0, OfficePhone = null, Remark = null }; _officeAppService.Add(model); return(Response(model.Id)); }
public IActionResult Edit([FromBody] OfficeViewModel officeViewModel) { try { var officeModel = Models.ObjectMapper <OfficeViewModel, Office> .Map(officeViewModel); if (_officeService.CheckDuplicate(officeModel) > 0) { var errorMessage = "Duplicate value entered for either code or name !!"; ModelState.AddModelError("", errorMessage); return(BadRequest(ModelState)); } if (ModelState.IsValid) { // var officeModelFromRepo = _officeService.GetOfficeDetailsById(OfficeModel.OfficeGuid); officeModel.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); officeModel.CreatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); officeModel.UpdatedBy = Guid.NewGuid(); // later comes through session.. var isOfficeUpated = _officeService.Edit(officeModel); if (isOfficeUpated >= 1) { _contractsService.UpdateAllUserByRole(officeModel.OperationManagerGuid, ContractUserRole._operationManager); } //audit log.. var additionalInformation = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Edited.ToString(), ResourceType.Office.ToString()); var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + "/admin/office"; var additionalInformationWithUri = string.Format("<a href=\"{0}\">{1}</a>", additionalInformationURl, additionalInformation); var resource = string.Format("{0} </br> GUID:{1} </br> Office Name:{2} </br> Office Code:{3}", ResourceType.Office.ToString(), officeModel.OfficeGuid, officeModel.OfficeName, officeModel.OfficeCode); AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), officeModel, resource, officeModel.OfficeGuid, UserHelper.GetHostedIp(HttpContext), "Office Edited", Guid.Empty, "Successful", "", additionalInformationWithUri, additionalInformationURl); return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Updated !!" })); } return(BadRequest(ModelState)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(BadRequestFormatter.BadRequest(this, e)); } }
public async Task <IActionResult> Create([FromForm] OfficeViewModel officesVM) { if (ModelState.IsValid) { var newOffice = await _officeRepo.AddOffice(officesVM.Office); TempData["message"] = "Your data has been submitted successfully."; TempData["toasterType"] = ToasterType.success; //return RedirectToAction(nameof(Index)); return(RedirectToAction(nameof(Edit), new { id = newOffice.Id, returnUrl = officesVM.ReturnUrl })); } TempData["message"] = "A problem has been ocurred while submitting your data."; TempData["toasterType"] = ToasterType.info; return(View("Edit", OfficeViewModelFactory.Create(officesVM.Office, officesVM.ReturnUrl))); }
public async Task <IActionResult> Edit([FromForm] OfficeViewModel officeVM) { if (ModelState.IsValid) { await _officeRepo.UpdateOffice(officeVM.Office); TempData["message"] = "Your data has been updated successfully."; TempData["toasterType"] = ToasterType.success; return(RedirectToAction(nameof(Edit), new { id = officeVM.Office.Id, returnUrl = officeVM.ReturnUrl })); } else { TempData["message"] = "A problem has been ocurred while updating your data."; TempData["toasterType"] = ToasterType.info; } return(View("Edit", OfficeViewModelFactory.Edit(officeVM.Office, officeVM.ReturnUrl))); }
public async Task <IActionResult> AddOffice([FromForm] OfficeViewModel model) { var addOfficeResponse = await _officeService.AddOffice(model); if (!addOfficeResponse.Result) { return(BadRequest(new ResponseViewModel { Message = addOfficeResponse.Message })); } else { return(Ok(new ResponseViewModel { Message = addOfficeResponse.Message })); } }
public ActionResult Add() { OfficeViewModel officeViewModel = new OfficeViewModel(); try { officeViewModel.PhysicalCountryId = _countryService.GetCountryGuidBy3DigitCode("USA"); officeViewModel.MailingCountryId = _countryService.GetCountryGuidBy3DigitCode("USA"); officeViewModel.CountrySelectListItems = _countryService.GetCountryList().ToDictionary(x => x.CountryId, x => x.CountryName); officeViewModel.StatePrimarySelectListItems = _stateService.GetStateByCountryGuid(officeViewModel.PhysicalCountryId).ToDictionary(x => x.StateId, x => x.StateName); officeViewModel.StateMailingSelectListItems = _stateService.GetStateByCountryGuid(officeViewModel.MailingCountryId ?? Guid.Empty).ToDictionary(x => x.StateId, x => x.StateName); officeViewModel.UserSelectListItems = _userService.GetUsers().ToDictionary(x => x.UserGuid, x => x.DisplayName); return(PartialView(officeViewModel)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(officeViewModel)); } }
public ActionResult Edit(Guid id) { OfficeViewModel officeViewModel = new OfficeViewModel(); try { var officeModel = _officeService.GetById(id); officeViewModel = Models.ObjectMapper <Office, OfficeViewModel> .Map(officeModel); officeViewModel.CountrySelectListItems = _countryService.GetCountryList().ToDictionary(x => x.CountryId, x => x.CountryName); officeViewModel.StatePrimarySelectListItems = _stateService.GetStateByCountryGuid(officeViewModel.PhysicalCountryId).ToDictionary(x => x.StateId, x => x.StateName); officeViewModel.StateMailingSelectListItems = _stateService.GetStateByCountryGuid(officeViewModel.MailingCountryId ?? Guid.Empty).ToDictionary(x => x.StateId, x => x.StateName); officeViewModel.UserSelectListItems = _userService.GetUsers().ToDictionary(x => x.UserGuid, x => x.DisplayName); return(PartialView(officeViewModel)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(officeViewModel)); } }
public void GetOfficeListCommand_PopulatesOfficesPropertyWithExpectedCollectionFromDataStore() { for (var i = 1; i < 4; ++i) { _mock.Object.CreateOffice( new Office { StreetNumber = 124, StreetName = "rue Saint André", City = "Lille", ZipCode = 59800 } ); } var viewModel = new OfficeViewModel(_mock.Object); viewModel.GetOfficeListCommand.Execute(null); Assert.IsTrue(viewModel.Offices.Count == 3); }
public async Task <ActionResult> Create(OfficeViewModel office) { if (!ModelState.IsValid) { return(View(office)); } //office with such name found in db if (_db.Offices.Any(o => o.Name == office.Name)) { return(new HttpStatusCodeResult(HttpStatusCode.Conflict)); } var newOffice = new Office { Name = office.Name }; _db.Offices.Add(newOffice); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Details(Guid id) { if (id == null) { return(NotFound()); } var item = await _context.LookupOffices.AsNoTracking() .Include(e => e.MasterUser) .Where(m => m.Id == id) .SingleOrDefaultAsync(); if (item == null) { return(NotFound()); } var model = new OfficeViewModel(item); return(View(model)); }