Example #1
0
        public JsonResult Problem_Insert(Guid customerID, string problemTitle, string problemDescription, short priority, short state)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check

            bool hasPermission = GetEmployee().IsGuaranteed("Problem_Insert");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            #endregion

            AddProblemRequest request = new AddProblemRequest();
            request.CreateEmployeeID   = GetEmployee().ID;
            request.ProblemTitle       = problemTitle;
            request.CustomerID         = customerID;
            request.ProblemDescription = problemDescription;
            request.Priority           = priority;
            request.State = state;

            response = this._problemService.AddProblem(request);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public GeneralResponse AddProblem(AddProblemRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                // چک کردن اینکه آیا در این مرحله امکان افزودن مشکل وجود دارد یا خیر
                Customer customer = this._customerRepository.FindBy(request.CustomerID);
                Level    level    = _levelRepository.FindBy(customer.Level.ID);
                if (level.Options == null || !level.Options.CanAddProblem)
                {
                    response.ErrorMessages.Add("ProblemIsNotPermitedInThisLevel");
                    return(response);
                }

                Problem problem = new Problem();
                problem.ID                 = Guid.NewGuid();
                problem.CreateDate         = PersianDateTime.Now;
                problem.CreateEmployee     = _employeeRepository.FindBy(request.CreateEmployeeID);
                problem.Customer           = this._customerRepository.FindBy(request.CustomerID);
                problem.Priority           = request.Priority;
                problem.ProblemDescription = request.ProblemDescription;
                problem.ProblemTitle       = request.ProblemTitle;
                problem.State              = request.State;
                problem.RowVersion         = 1;

                _problemRepository.Add(problem);
                _uow.Commit();

                ////response.success = true;

                // Validation
                if (problem.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in problem.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }
        public async Task <ActionResult <CustomResponse> > Add(
            [FromRoute][BindRequired][ModelBinder(Name = "problemsetId")] Problemset problemset,
            [FromBody] AddProblemRequest request
            )
        {
            var problem = await objectService.GetObject(dbContext, request.ProblemId) as IProblem;

            if (problem == null)
            {
                ModelState.AddModelError("ProblemId", "Problem does not exist.");
                return(BadRequest(ModelState));
            }
            await problemset.AddProblem(problem, request.Identifier);

            return(new CustomResponse());
        }