public IActionResult Create(DepartmentViewModel viewModel) { if (ModelState.IsValid) { var command = Mapper.Map<NewDepartmentCommand>(viewModel); _commandService.Handle(command); return RedirectToAction("Index").WithSuccess("Department created successfully."); } else { return View(viewModel).WithError("Validation error occured."); } }
public IHttpActionResult Get(string id) { try { DepartmentViewModel dep = new DepartmentViewModel(); dep.DepartmentId = id; dep.GetById(); return Ok(dep); } catch (Exception ex) { return BadRequest("Retrive failed - " + ex.Message); } }
public ActionResult Create(DepartmentViewModel viewModel) { try { if (!ModelState.IsValid) return View(viewModel); var department = Mapper.Map<DepartmentViewModel, Department>(viewModel); _departmentService.Add(department); return RedirectToAction("Index"); } catch { return View(viewModel); } }
public ActionResult Edit(int id, DepartmentViewModel model) { if (ModelState.IsValid) { var department = db.Departments.Find(id); if (department != null) { department.DepartmentName = model.DepartmentName; db.SaveChanges(); return(RedirectToAction("Index")); } else { return(HttpNotFound()); } } else { return(View(model)); } }
// GET: Departments/Edit/5 public ActionResult Edit(int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Department department = _departmentManager.FindById((int)id); if (department == null) { return(HttpNotFound()); } ViewBag.OrganizationId = new SelectList(_organizationManager.GetAll(), "Id", "Name", department.OrganizationId); DepartmentViewModel departmentViewMode = Mapper.Map <DepartmentViewModel>(department); return(View(departmentViewMode)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Departments", "Edit"))); } }
public ActionResult Create([Bind(Include = "DepartmentId,Name,ColourId")] Department department) { if (ModelState.IsValid) { var result = HRBusinessService.CreateDepartment(UserOrganisationId, department); if (result.Succeeded) { return(RedirectToAction("Index")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } var viewModel = new DepartmentViewModel { Department = department, ColoursList = HRBusinessService.RetrieveColours().ToList() }; return(View(viewModel)); }
public ActionResult AddDepartment(DepartmentViewModel model) { if (ModelState.IsValid) { DepartmentModel data = new DepartmentModel(); Mapper.Map(model, data); data.created_on = DateTime.Now; data.updated_on = DateTime.Now; data.VisibleOnDashboard = model.VisibleOnDashboard ?? false; data.Color = model.Color != null ? model.Color : "#0000FF"; idepartmentBusiness.AddDepartment(data); return(Json(new { success = true })); } else { return(BadRequest(ModelState)); } }
public async Task <ActionResult> Create(DepartmentViewModel model) { //Check the validity of the model if (ModelState.IsValid) { // call an instance of Driver Class var department = DepartmentFactory.ViewModelToDepartmentEntity(model); if (department != null) { _dbContext.Departments.Add(department); } await _dbContext.SaveChangesAsync(); Success("Department Creted Successfully", true); return(Json(new { success = true })); } return(PartialView("_Create", model));; }
public IHttpActionResult Put(DepartmentViewModel dep) { try { if (dep.Update() == 1) { return(Ok("Department " + dep.DepartmentName + " updated!")); } else if (dep.Update() == -1) { return(Ok("Department " + dep.DepartmentName + " not updated!")); } else { return(Ok("Data is stale for " + dep.DepartmentName + " data not updated!")); } } catch (Exception ex) { return(BadRequest("Update failed - " + ex.Message)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Department department = db.Departments.Find(id); if (department == null) { return(HttpNotFound()); } DepartmentViewModel model = new DepartmentViewModel { Id = department.DepartmentId, DepartmentName = department.DepartmentName }; return(View(model)); }
private DepartmentViewModel GetDepartment(int departmentid) { var item = Db.Get <Department>(departmentid); var model = new DepartmentViewModel(); Mapper.Map(item, model); IEnumerable <string> files = new List <string>(); try { var directory = new DirectoryInfo(Server.MapPath(model.FilesFolder)); files = directory.GetFiles().Select(f => f.Name); } catch (Exception ex) { } model.Files = files; return(model); }
// GET: Departments/Details/5 public ActionResult Details(int?id) { try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Department department = _departmentManager.FindById((int)id); if (department == null) { return(HttpNotFound()); } DepartmentViewModel departmentViewMode = Mapper.Map <DepartmentViewModel>(department); return(View(departmentViewMode)); } catch (Exception ex) { ExceptionMessage(ex); return(View("Error", new HandleErrorInfo(ex, "Departments", "Details"))); } }
public async Task <IActionResult> Edit(DepartmentViewModel model) { var companies = await _context.Companies.ToListAsync(); ViewBag.Company = companies; if (ModelState.IsValid) { Department department = new Department() { Id = model.Id, Name = model.Name, CompanyId = model.CompanyId }; _context.Departments.Update(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(List))); } return(View()); }
public ActionResult Create(DepartmentViewModel model) { try { bool result = _DepartmentService.AddDepartment(model); if (result) { Alert("Congratulations", "Department successfully added!", NotificationType.success); } else { Alert("Error", "Department Failed to be added!", NotificationType.error); } return(RedirectToAction(nameof(Index))); throw new Exception(); } catch { return(View()); } }
public ActionResult Edit(DepartmentViewModel dvm) { var dept = new CYBInfracstructure.DataStructure.Entities.Department { DepartmentName = dvm.DepartmentName, Id = dvm.Id, LocationId = dvm.LocationId, IsActive = dvm.IsActive, Date = dvm.Date }; if (TryUpdateModel(dept)) { _department.Edit(dept); _department.SaveChanges(); TempData["Success"] = "Edited Successfully!"; //TempData["Message"] = "Client Details Edited Successfully"; return(RedirectToAction("Index")); } return(View()); }
public ActionResult SaveStatus(DepartmentViewModel model) { statusService = new StatusService(context); delegationService = new DelegationService(context); bool status = false; Delegation delegation = delegationService.FindDelegationByDelegationId(model.DelegationId); delegation.Status = statusService.FindStatusByStatusId(model.DelegationStatus); //delegation.UpdatedBy = user; delegation.CreatedBy = userService.FindUserByEmail(CurrentUserName); delegation.UpdatedDateTime = DateTime.Now; if (delegationService.DelegateManager(delegation) != null) { status = true; } return(new JsonResult { Data = new { status = status } }); }
public void DeleteDepartment() { using (FakeEmployeeContext ctx = BuildContextWithData()) { DepartmentWorkspaceViewModel vm = BuildViewModel(ctx); vm.CurrentDepartment = vm.AllDepartments.First(); DepartmentViewModel toDelete = vm.CurrentDepartment; int originalCount = vm.AllDepartments.Count; string lastProperty = null; vm.PropertyChanged += (sender, e) => { lastProperty = e.PropertyName; }; vm.DeleteDepartmentCommand.Execute(null); Assert.AreEqual(originalCount - 1, vm.AllDepartments.Count, "One department should have been removed from the AllDepartments property."); Assert.IsFalse(vm.AllDepartments.Contains(toDelete), "The selected department should have been removed."); Assert.IsFalse(ctx.IsObjectTracked(toDelete.Model), "The selected department has not been removed from the UnitOfWork."); Assert.IsNull(vm.CurrentDepartment, "No department should be selected after deletion."); Assert.AreEqual("CurrentDepartment", lastProperty, "CurrentDepartment should have raised a PropertyChanged."); } }
// GET: Departments/Edit/5 public async Task <IActionResult> Edit(int?id) { DepartmentViewModel vm; if (id == 0) { vm = new DepartmentViewModel(_context); } else { var department = await _context.Department.FindAsync(id); if (department == null) { return(NotFound()); } vm = new DepartmentViewModel(_context, department); } return(View(vm)); }
public async Task <IActionResult> Index() { using (IDbConnection conn = Connection) { string sql = @"SELECT d.Id, d.Name, d.Budget, count(e.Id) TotalEmployees FROM Department d left join Employee e on d.Id = e.DepartmentId group by d.Id, d.Name, d.Budget "; IEnumerable <Department> depoWithEmpCount = await conn.QueryAsync <Department>(sql); DepartmentViewModel model = new DepartmentViewModel(); model.departments = depoWithEmpCount.ToList(); return(View(model)); } }
public void TestUpdateShouldReturnOk() { DepartmentViewModel vm = new DepartmentViewModel(); vm.Id = id_string; vm.GetById(); vm.DepartmentName = "dep name changed"; int ver = vm.Version; Assert.IsTrue(vm.Update() == (int)UpdateStatus.Ok); vm.GetById(); // get updated version Assert.IsTrue(vm.Version == ver + 1); Assert.IsTrue(vm.DepartmentName == "dep name changed"); // change it back vm.DepartmentName = dep_name; Assert.IsTrue(vm.Update() == (int)UpdateStatus.Ok); vm.GetById(); Assert.IsTrue(vm.Version == ver + 2); Assert.IsTrue(vm.DepartmentName == dep_name); } // TestUpdateShouldReturnOk
// GET: Department/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var q = from d in db.Departments join x in db.Departments on d.ParentDepartmentId equals x.Number where d.Number == id select new DepartmentViewModel { Number = d.Number, Name = d.Name, Remark = d.Remark, ParentDepartmentName = x.Name, StaffSize = x.StaffSize } ; DepartmentViewModel department = q.FirstOrDefault(); if (department == null) { return(HttpNotFound()); } return(View(department)); }
public HttpResponseMessage Post(HttpRequestMessage request, DepartmentViewModel departmentVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { Department newDepartment = new Department(); newDepartment.UpdateDepartment(departmentVm); var responseData = _departmentService.Add(newDepartment); _departmentService.Save(); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
//Registra un nuevo departamento public ResponseViewModel Register(DepartmentViewModel model) { //variables var _result = new ResponseViewModel(); DateTime now = DateTime.Today; try { //map entity var entity = Map.ViewModelToEntity(model); //Crear registro var respuesta = Repository.Register(entity); //valida la respuesta if (respuesta != null) { List <DepartmentViewModel> _list = new List <DepartmentViewModel>(); _list.Add(Map.EntityToViewModel(entity)); _result.Message = string.Format("Se ha creado el departamento {0}", entity.Nombre); _result.Data = _list.OfType <object>().ToList(); _result.Success = true; } else { _result.Message = "Ha ocurrido un error"; _result.Success = false; } } catch (Exception ex) { _result.Message = ex.Message; _result.Success = false; } return(_result); }
/// <summary> /// Get Department by id /// </summary> /// <param name="id">ID of Department</param> /// <returns></returns> public ApiResponseViewModel GetById(int id) { var result = new DepartmentViewModel(); var response = new ApiResponseViewModel { Code = CommonConstants.ApiResponseSuccessCode, Message = null, Result = null }; try { var exists = _departmentRepository.CheckContains(m => m.ID == id); if (exists) { var tempResult = _departmentRepository.GetSingleById(id); result.ID = tempResult.ID; result.DepartmentName = tempResult.DepartmentName; result.CompanyID = tempResult.CompanyID; result.Address = tempResult.Address; result.Company = tempResult.Company.CompanyName; result.IsActive = tempResult.IsActive ?? false; response.Result = result; } else { response.Code = CommonConstants.ApiResponseNotFoundCode; response.Message = CommonConstants.NotFoundMessage; } } catch (Exception ex) { response.Code = CommonConstants.ApiResponseExceptionCode; response.Message = CommonConstants.ErrorMessage + " " + ex.Message; } return(response); }
public ActionResult Edit(int id, DepartmentViewModel DeptVM) { DeptVM.MyList = new SelectList(from s in db.Employees.ToList() select new { EmplyeeId = s.EmployeeId, FullName = s.FirstName + " " + s.LastName }, "EmplyeeId", "FullName", new { DeptVM.EmployeeId }); if (ModelState.IsValid) { var loc = TempData["GetLocation"].ToString(); var emp = int.Parse(TempData["EmpID"].ToString()); var Dept = db.Departments.Find(id); Dept.Name = DeptVM.Name; ////var DeptLocation = db.DepartmentLocations.Where(x=>x.DepartmentID == id && x.Location == loc).FirstOrDefault(); ////DeptLocation.DepartmentID = DeptVM.DepartmentID; ////DeptLocation.Location = DeptVM.Location; //var DeptManager = db.DepartmentManagers.Where(x=>x.DepartmentID == id && x.EmployeeId == emp).FirstOrDefault(); //DeptManager.EmployeeId = DeptVM.EmployeeId; //DeptManager.StartDate = DeptVM.StartDate; //db.Entry(Dept).State = EntityState.Modified; //db.Entry(DeptLocation).State = EntityState.Modified; //db.Entry(DeptManager).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(DeptVM)); }
// GET: Departments/Edit/5 /// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>IActionResult.</returns> public async Task <IActionResult> Edit(int?id) { DepartmentViewModel model = new DepartmentViewModel(); if (id == null) { return(NotFound()); } var department = await _context.Department.FindAsync(id); if (id != null) { model.DeptName = department.DeptName; } if (department == null) { return(NotFound()); } ViewData["DivisionId"] = new SelectList(_context.Division, "Id", "DivisionName", department.DivisionId); return(View(department)); }
public ActionResult CreateDepartment(DepartmentViewModel department) { if (!ModelState.IsValid) { ViewBag.Error = "Nieprawidłowe dane"; return(View()); } if (db.Departments.Any(x => x.Name == department.Name)) { ViewBag.Error = "Oddział już istnieje"; return(View()); } Department newDep = new Department() { Name = department.Name, Location = department.Location }; db.Departments.Add(newDep); db.SaveChanges(); ViewBag.Success = "Operacja wykonana pomyślnie"; return(View()); }
public static DepartmentViewModel GetById(int id) { DepartmentViewModel result = new DepartmentViewModel(); using (var db = new PayrollContext()) { result = (from d in db.Department //join div in db.Division on //d.DivisionId equals div.Id where d.Id == id select new DepartmentViewModel { Id = d.Id, Code = d.Code, DivisionId = d.DivisionId, //DivisionCode = div.Code, //DivisionName = div.Description, Description = d.Description, IsActivated = d.IsActivated }).FirstOrDefault(); } return(result); }
/// <summary> /// 根据搜索条件获取院系信息列表数目 /// </summary> /// <param name="webModel">院系列表页视图模型</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public static async Task <int> GetListCountAsync(DepartmentViewModel webModel, ApplicationDbContext context) { if (string.IsNullOrEmpty(webModel.SId) && string.IsNullOrEmpty(webModel.SName) && string.IsNullOrEmpty(webModel.STel)) { var list = await context.Set <Department>().AsNoTracking().OrderByDescending(i => i.CreatedOn).ToListAsync(); return(list.Count()); } else { IQueryable <Department> departments = context.Department.AsQueryable(); var predicate = PredicateBuilder.New <Department>(); //院系编号 if (!string.IsNullOrEmpty(webModel.SId)) { predicate = predicate.And(i => i.Id == Convert.ToInt64(webModel.SId)); } //院系名称 if (!string.IsNullOrEmpty(webModel.SName)) { predicate = predicate.And(i => i.Name == webModel.SName); } //院系联系方式 if (!string.IsNullOrEmpty(webModel.STel)) { predicate = predicate.And(i => i.Tel == webModel.STel); } var list = await departments.AsExpandable().Where(predicate).ToListAsync(); return(list.Count()); } }
public ActionResult Create(DepartmentViewModel dvm) { try { activeUser = userBll.GetUserById((long)HttpContext.Session.GetInt32("userId")); ViewData["sessionData"] = new int?[] { HttpContext.Session.GetInt32("admin"), HttpContext.Session.GetInt32("language") }; if (activeUser.Administrator > 0) { Department department = new Department { Name = dvm.Name, DepartmentCode = dvm.DepartmentCode, FloorId = dvm.FloorId, Svg = dvm.Svg }; departmentBll.CreateDepartment(department); long departmentId = departmentBll.ShowAllDepartments().FirstOrDefault(d => d.DepartmentCode == department.DepartmentCode).DepartmentId; for (int i = 1; i < dvm.NumberOfDesks + 1; i++) { FlexDesk desk = new FlexDesk(); desk.DepartmentId = departmentId; desk.FlexDeskCode = department.DepartmentCode + i.ToString("000");; desk.Name = department.Name + " " + i.ToString("000"); flexDeskBll.CreateFlexDesk(desk); } } return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Index))); } }
public IActionResult Department(DepartmentViewModel model) { string failureMessage = null; string successMessage = null; var redirectUrl = "/ManageSite/Department"; if (ModelState.IsValid) { var result = ManageSiteHelper.AddDepartment(model, _context); if (result == UpdateResult.Error) { failureMessage = "Department couldn't be updated."; } else if (result == UpdateResult.Success) { successMessage = "Department updated."; } else if (result == UpdateResult.Duplicate) { failureMessage = "Department already exists."; } } if (!string.IsNullOrWhiteSpace(failureMessage)) { redirectUrl += string.Format("?failureMessage={0}", failureMessage); } if (!string.IsNullOrWhiteSpace(successMessage)) { redirectUrl += string.Format("?successMessage={0}", successMessage); } return(ControllerHelper.RedirectToLocal(this, redirectUrl)); }
public HttpResponseMessage Put(int id, [FromBody] DepartmentViewModel departmentViewModel) { try { var temprole = AutoMapper.Mapper.Map <Department>(departmentViewModel); _department.UpdateDepartment(temprole); var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; return(response); } catch (Exception) { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }; return(response); } }
public IActionResult Save(DepartmentViewModel model) { if (ModelState.IsValid) { var department = new Department { Id = model.Id, Description = model.Description, }; if (model.Id.ToString().Length <= 0) { _Department.Add(department); } else { _Department.Update(department); } return(RedirectToAction("Index")); } else { return(View()); } }
public ActionResult Delete(int id, DepartmentViewModel viewModel) { try { _departmentService.Delete(id); return RedirectToAction("Index"); } catch { return View(viewModel); } }