Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] DepartmentCreateDTO departmentDTO)
        {
            try
            {
                _logger.LogInfo($"Department submission attempted.");
                if (departmentDTO == null)
                {
                    _logger.LogWarn($"Empty Request was submitted.");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn($"Department Data was Invalid.");
                    return(BadRequest(ModelState));
                }
                var department = _mapper.Map <Department>(departmentDTO);
                var isSuccess  = await _departmentRepository.Create(department);

                if (!isSuccess)
                {
                    return(InternalError($"Department creation failed."));
                }
                _logger.LogInfo("Department created");
                return(Created("Create", new { department }));
            }
            catch (Exception e)
            {
                return(InternalError($"{e.Message} - {e.InnerException}"));
            }
        }
        public Result <ApplicationResult <DepartmentDto> > Create(DepartmentCreateDto departmentDto)
        {
            var applicationResult = new ApplicationResult <DepartmentDto>();

            _codeBuilder.Build("DE1", "DE")
            .OnSuccess(resultCode => DepartmentEdit.Create(resultCode, departmentDto.Name, departmentDto.Description))
            .OnSuccess(resultDepartment => {
                if (resultDepartment.IsValid)
                {
                    _departmentRepository.Create(resultDepartment)
                    .OnSuccess(() =>
                    {
                        var dto = Mapper.Map <DepartmentDto>(resultDepartment);

                        applicationResult.IsValid = true;
                        applicationResult.Entity  = dto;
                    });
                }
                else
                {
                    applicationResult.IsValid = false;
                    foreach (var error in resultDepartment.BrokenRules.Errors)
                    {
                        applicationResult.ErrorMessages.Add(new ErrorMessage {
                            Code = error.ErrorCode, Message = error.ErrorMessage
                        });
                    }
                }
            });

            return(applicationResult.ToResult());
        }
        public ActionResult <Department> PostDepartment(Department Department)
        {
            departmentRepo.Create(Department);
            DB.SaveChanges();

            return(CreatedAtAction("GetDepartment", new { id = Department.Id }, Department));
        }
        public ActionResult Create(DepartmentViewModel model)
        {
            try
            {
                // TODO: Add insert logic here
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var Department = _mapper.Map <Department>(model);
                var isSuccess  = _repo.Create(Department);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong!");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Something Went Wrong!");
                return(View(model));
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Create(DepartmentViewModel viewModel)
        {
            User manager = await _userRepository.GetByGuid(viewModel.DepartmentHeadId);

            Department department = _mapper.ConvertFromViewModel(viewModel, manager);
            await _departmentRepository.Create(department);

            return(RedirectToAction(nameof(Index), "Department"));
        }
        public DepartmentDTO Create(DepartmentDTO objet)
        {
            Department entite   = MapDepartment.ToEntity(objet, true);
            Department resultat = _repo.Create(entite);

            objet = MapDepartmentDTO.ToDto(resultat);

            return(objet);
        }
Beispiel #7
0
        public IActionResult CreateDepartment(Department department)
        {
            var create = _departmentRepository.Create(department);

            if (create > 0)
            {
                return(Ok(create));
            }
            return(BadRequest("Not Successfully"));
        }
        public IActionResult Post(Department department)
        {
            var post = _departmentRepository.Create(department);

            if (post > 0)
            {
                return(Ok(post));
            }
            return(BadRequest("Can't be created"));
        }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "Id,Name,Budget,StartDate,InstructorID")] Department department)
        {
            if (ModelState.IsValid)
            {
                _departmentRepository.Create(department);
                return(RedirectToAction("Index"));
            }

            PopulateInstructorDropDownList(department.InstructorId.Value);
            return(View(department));
        }
        public Department CreateDepartment(Department Department)
        {
            if (_departmentRepository.GetDepartmentByName(Department.Name) != null)
            {
                return(null);
            }

            _departmentRepository.Create(Department);
            _departmentRepository.SaveChanges();
            return(Department);
        }
Beispiel #11
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _repository.Create(Department);

            return(RedirectToPage("Index"));
        }
        public override ActionResult Add(AddOrEditViewModel <Department> model, FormCollection collection)
        {
            if (!ModelState.IsValid)
            {
                ModelErrorMsg();
                return(View("AddOrEdit", model));
            }
            repo.Create(model.Entity);
            repo.Context.Commit();

            return(RedirectToAction("Index", new { currentPageNum = model.CurrentPageNum, pageSize = model.PageSize }));
        }
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                repository.Create(department);

                TempData["message"] = "Кафедра успешно добавлена";

                return(RedirectToAction("Index"));
            }
            ViewBag.FacultyId = new SelectList(db.Faculties, "Id", "Name", department.FacultyId);
            return(View(department));
        }
Beispiel #14
0
        public ActionResult Update(DepartmentModel departmentModel)
        {
            ApiResult <Department> apiResult;

            if (ModelState.IsValid)
            {
                if (departmentModel.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var department = new Department {
                            Title       = departmentModel.Title,
                            ParentId    = departmentModel.ParentId,
                            Description = departmentModel.Description,
                            MailAlias   = departmentModel.MailAlias,
                            Id          = departmentModel.Id
                        };
                        _departmentRepository.Update(department);
                        _unitOfWork.Commit();
                        return(department);
                    }, "Department updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var department = new Department
                        {
                            Title       = departmentModel.Title,
                            ParentId    = departmentModel.ParentId,
                            Description = departmentModel.Description,
                            MailAlias   = departmentModel.MailAlias
                        };
                        _departmentRepository.Create(department);
                        _unitOfWork.Commit();
                        return(department);
                    }, "Department created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <Department>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
Beispiel #15
0
 public async Task <int> CreateDepartmentAsync(DepartmentModelRq model, UserIdentity <int> issuer)
 {
     try
     {
         var entity = _mapper.Map <Department>(model);
         _departmentRepository.Create(entity);
         entity.CreateBy(issuer).UpdateBy(issuer);
         if (await _uow.SaveChangesAsync() == 1)
         {
             return(entity.Id);
         }
         return(0);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public async Task <ActionResult> CreateNewDepartment(Department department)
        {
            try
            {
                if (department == null)
                {
                    return(BadRequest());
                }
                var departmentCreated = await _repository.Create(department);

                return(CreatedAtAction(nameof(GetDepartmentById), new { id = departmentCreated.DepartmentId }, departmentCreated));
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "There were error in creating new department, Please contact your admin!"));
            }
        }
Beispiel #17
0
 public IActionResult Create(Department department, bool check)
 {
     try {
         ViewBag.Error = null;
         if (ModelState.IsValid)
         {
             deptManager.Create(department, check);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     catch
     {
         ViewBag.Error = "Department with the same code or name already exists.";
         return(View());
     }
 }
Beispiel #18
0
        public async Task <ActionResult <Department> > PostDepartment(Department department)
        {
            try
            {
                var response = await _departmentRepository.Create(department);

                if (response > 0)
                {
                    return(CreatedAtRoute(nameof(GetDepartmentById), new { departmentId = department.Id }, department));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                return(Problem(ex.Message));
            }
        }
        public ActionResult Create(DepartmentVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var department = _mapper.Map <Department>(model);
                var isSuccess  = _repo.Create(department);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong...");
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #20
0
        public IActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                var entity = new Department()
                {
                    Name = department.Name,
                };

                _departmentRepository.Create(entity);

                var msg = new AlertMessage()
                {
                    Message   = $"{entity.Name} departmanı eklendi",
                    AlertType = "success"
                };
                TempData["message"] = JsonConvert.SerializeObject(msg);

                return(RedirectToAction("Index"));
            }
            return(View(department));
        }
Beispiel #21
0
        public async Task Execute(CreateDepartmentInput input)
        {
            if (input == null)
            {
                createDepartmentOutputPort.WriteError("Department is empty"); return;
            }


            // Vajno!!!
            //  var user = findUser trtatata

            bool isSuccess = await departmentRepository.Create(new Department()
            {
                Head = new User()
                {
                    Id = input.HeadId
                },
                Name = input.Name
            });

            createDepartmentOutputPort.Standart(new CreateDepartmentOutput(isSuccess));
        }
        public async Task <ActionResult <Department> > PostDepartment(Department department)
        {
            department = await _departmentRepository.Create(department);

            return(department);
        }
Beispiel #23
0
 public bool Create(Department department)
 {
     return(depRep.Create(department));
 }
Beispiel #24
0
 public void Create(Department department)
 {
     _departmentRepository.Create(department);
 }
 public Department AddNewDepartment(Department department) => departmentRepository.Create(department);
 public void CreateDepartment(Department department)
 {
     _departmentRepository.Create(department);
     _departmentRepository.Save();
 }
 public void Add(Department item)
 {
     _repository.Create(item);
 }
Beispiel #28
0
 public bool Create(DepartmentModel model)
 {
     return(_res.Create(model));
 }