public async Task <ActionResult <Department> > AddDepartment(Department department) { try { if (department == null) { return(BadRequest()); } Department dep = await departmentRepository.GetDepartment(department.DepartmentId); if (dep.DepartmentName == department.DepartmentName) { ModelState.AddModelError("DepartmentName", "Le pole existe déjà"); return(BadRequest(ModelState)); } Department departmentCreated = await departmentRepository.AddDepartment(department); return(CreatedAtAction(nameof(GetDepartment), new { id = departmentCreated.DepartmentId }, departmentCreated)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Impossible de créer le pole ")); } }
public async Task <IActionResult> AddNewDepartment([FromBody] CreateDepartmentRequestModel departmentCreateRequestModel) { try { System.Threading.Thread.Sleep(1000); var departmentExists = await _departmentRepository.DepartmentExists(departmentCreateRequestModel.DepartmentName); if (departmentExists) { return(BadRequest(new ApiResponseBadRequestResult() { ErrorMessage = $"Department {departmentCreateRequestModel.DepartmentName} already exists" })); } var newDepartment = await _departmentRepository.AddDepartment(_mapper.Map <Department>(departmentCreateRequestModel)); return(Ok(new ApiResponseOKResult() { Data = newDepartment })); } catch (Exception ex) { _logger.LogError(ex, "Failed to create new department"); return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponseFailure() { ErrorMessage = "Failed to create new department" })); } }
public async Task OnSaveDepartment() { Department.Name = Name; Department.Code = Code; try { Department = await _departmentRepository.AddDepartment(Department); } catch (DbException ex) { Console.WriteLine(ex.Message); } if (Professor.Id != 0) { var profDep = new ProfessorDepartment() { DepartmentId = Department.Id, ProfessorId = Professor.Id, IsHead = true }; try { await _departmentRepository.ProfessorDepartment(profDep); } catch (DbException ex) { Console.WriteLine(ex.Message); } } await OnCancel(); }
public IActionResult AddDepartment(Department department) { try { var result = _departmentResitory.AddDepartment(department); if (result) { return(Json(new { result = 1, message = "修改成功", data = true }, new JsonSerializerSettings() )); } else { return(Json(new { result = 0, message = "修改失败", data = false }, new JsonSerializerSettings() )); } } catch (Exception exc) { return(Json(new { result = 0, message = $"修改失败:{exc.Message}" }, new JsonSerializerSettings())); } }
private void AddNewDepartment(string departmentName) { var newDept = new Department { Name = departmentName }; _departmentRepository.AddDepartment(newDept); }
public IActionResult Add([Bind("Did,DepartmentName")] Department department) { if (department.Did == 0) { _departmentRepository.AddDepartment(department); } else { _departmentRepository.UpdateDepartment(department); } return(RedirectToAction(nameof(Index))); }
public IActionResult AddDepartment(string dept) { if (departmentRepository.AddDepartment(dept)) { TempData["message"] = "Роздел успешно добавлен"; } else { TempData["BadMessage"] = "Произошла ошибка, возможно раздел уже существует"; } return(RedirectToAction("Outfits")); }
public async Task <IActionResult> Create(Department department) { try { await _repository.AddDepartment(department); return(Ok(department)); } catch { return(BadRequest()); } }
public IActionResult AddDepartment(Department deparment) { try { var result = _departmentRepository.AddDepartment(deparment); _logger.LogInformation($"添加部门:{(result ? "添加成功" : "添加失败")}"); return(ToJson(result ? BackResult.Success : BackResult.Fail, message: result ? "添加成功" : "添加失败")); } catch (Exception exc) { _logger.LogCritical(exc, $"添加部门:{ exc.Message}"); return(ToJson(BackResult.Exception, message: exc.Message)); } }
public IActionResult Create([Bind("DepartmentId,Name,ModifiedDate,CreatedDate,Status")] Department department) { if (ModelState.IsValid) { var(error, _) = _departmentRepository.AddDepartment(department); if (error != null) { return(StatusCode(500, error.ToString())); } return(RedirectToAction(nameof(Index))); } return(View(department)); }
public ActionResult Create(Course c, string departmentList, string yearList) { var result = _departmentRepository.GetDepartmentByName(departmentList); if (result != null) { c.DepartmentId = result.Id; c.Year = yearList; } _departmentRepository.AddDepartment(result); return(RedirectToAction("Index", "Course")); }
//protected bool ValidateDepartment(Department departmentToValidate) //{ // if (departmentToValidate.Name.Trim().Length == 0) // _modelState.AddModelError("Name", "Name is required."); // return _modelState.IsValid; //} public async Task <bool> AddDepartment(Department departmentToCreate) { //if (!ValidateDepartment(departmentToCreate)) // return false; try { await _departmentRepository.AddDepartment(departmentToCreate); } catch { return(false); } return(true); }
public IActionResult Create(Department model) { if (ModelState.IsValid) { Department department = new Department { DepartmentName = model.DepartmentName }; departmentRepository.AddDepartment(department); return(RedirectToAction("Index")); } return(View(model)); }
public void AddDepartment(DepartmentViewModel obj) { Department departmentobj = new Department(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <DepartmentViewModel, Department>(); cfg.IgnoreUnmapped(); }); IMapper mapper = config.CreateMapper(); departmentobj = mapper.Map <DepartmentViewModel, Department>(obj); departmentRepository.AddDepartment(departmentobj); }
public async Task <ActionResult> AddProjectMilestone(Department model) { if (ModelState.IsValid) { try { return(Ok(await _repository.AddDepartment(model))); } catch (Exception ex) { throw new JsonException(ex.Message, ex); } } return(BadRequest()); }
public HttpResponseMessage AddDepartment(DepartmentVM model) { try { var response = _repo.AddDepartment(model); if (response == false) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = "No record found" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result = response })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = ex.Message })); } }
public async Task <ActionResult <Department> > CreateDepartment(Department department) { try { if (department == null) { return(BadRequest()); } var createdDepart = await departmentRepository.AddDepartment(department); return(CreatedAtAction(nameof(GetById), new { id = createdDepart.DeptId }, createdDepart)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retriving data ")); } }
public async Task <ActionResult <Department> > PostDepartment(Department department) { try { if (department == null) { return(BadRequest()); } var emp = await dept.AddDepartment(department); return(CreatedAtAction("GetDepartment", new { id = department.DepartmentId }, department)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database")); } }
public IHttpActionResult PostDepartment([FromBody] Department department) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repository.AddDepartment(department); return(CreatedAtRoute("DefaultApi", new { id = department.Id }, department)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task AddDepartment(AddDepartmentDto department) { var depart = await _departmentRepository.GetByName(department.Name); if (depart != null) { throw new Exception("This department is used"); } var newDepartment = new Department(); newDepartment.Id = Guid.NewGuid(); newDepartment.Name = department.Name; newDepartment.PhoneNumber = department.PhoneNumber; newDepartment.Descriptcion = department.Description; await _departmentRepository.AddDepartment(newDepartment); }
public IActionResult Post([FromBody] Department dept) { if (dept == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_deptrepo.AddDepartment(dept)) { return(StatusCode(500, "A problem happened while handling your request.")); } else { return(StatusCode(201, "Created Successfully")); } }
public async Task <short> Handle(CreateDepartment request, CancellationToken cancellationToken) { TblDepartment entity; if (request.id > 0) { entity = _departmentRepository.FindById(request.id); } else { entity = new TblDepartment(); } entity.departmentName = request.department; var department = (entity.id == 0) ? _departmentRepository.AddDepartment(entity) : _departmentRepository.EditDepartment(entity); //entity.gid = await _eventStoreService.createStream(entity); var saved = await _unitOfWork.CommitAsync(); /* s.n todo handle saved result*/ return(department.id); }
public async Task <IActionResult> AddDepartment([FromBody] DepartmentViewModel departmentViewModel) { if (ModelState.IsValid) { try { var departmentObject = await deptRepository.AddDepartment(departmentViewModel); return(Ok(departmentObject)); } catch (Exception) { if (departmentViewModel.DepartmentName == null) { return(StatusCode(400, " Department Name is not provided")); } } } return(BadRequest()); }
public async Task <IActionResult> AddDepartment([FromBody] Department model) { if (ModelState.IsValid) { try { var departmentId = await _departmentRepository.AddDepartment(model); if (departmentId > 0) { return(Ok(departmentId)); } return(NotFound()); } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public async Task <bool> AddAllEntitiesAsync() { // create new Department var departMentName = $"department_{Guid.NewGuid():N}"; var department = _departmentRepository.AddDepartment(departMentName); // create new User with above Department var userName = $"user_{Guid.NewGuid():N}"; var userEmail = $"{Guid.NewGuid():N}@gmail.com"; var user = _userRepository.NewUser(userName, userEmail, department); // create new Salary with above User float coefficientsSalary = new Random().Next(1, 15); float workdays = 22; var salary = _salaryRepository.AddUserSalary(user, coefficientsSalary, workdays); // Commit all changes with one single commit var saved = await _unitOfWork.CommitAsync(); return(saved > 0); }
public async Task <IActionResult> Add([FromBody] Department department) { ISingleModelResponse <Department> response = new SingleModelResponse <Department>(); try { Department de = await _departmentRepository.AddDepartment(department); response.Message = "Department added successfully"; response.Model = de; } catch (Exception ex) { _logger.LogError(entities.LoggingEvents.InsertItem, ex, "Error while adding department, Request: {0}", department); response.IsError = true; response.ErrorMessage = "Could not add department"; return(BadRequest(response)); } return(Ok(response)); }
public async Task <PostStatusCodesEnums> AddDepartment(IDepartment model) { var statusCode = await _repository.AddDepartment(model); return(statusCode); }
public IActionResult Post([FromBody] Department value) { _departmentsRepository.AddDepartment(value); return(CreatedAtAction("Get", new { id = value.ID }, value)); }
public JsonResult AddDepartment(DepartmentPocos department) { _departmentRepository.AddDepartment(department); return(Json(Url.Action("DepartmentList", "Department"))); }
public async Task <bool> Post([FromBody] Department item) { await _depRepository.AddDepartment(item); return(true); }