public IActionResult DetailProd(long?id)
        {
            ProductViewModel product = _context.Set <Product>().Select(p => new ProductViewModel
            {
                Id          = p.Id,
                Name        = p.Name,
                Description = p.Description,
                Price       = p.Price,
                Date        = p.Date,
                CategoryId  = p.CategoryId,
                ImageProd   = p.ImageProd ?? Consts.DefaultImageProd
            }).SingleOrDefault(c => c.Id == id);

            var responses = GetAllResponces(product.Id);
            var createResponceViewModel = new RespondViewModel {
                ProductId = product.Id
            };

            DetailRespondViewModel viewModel = new DetailRespondViewModel()
            {
                ProductViewModel       = product,
                Responses              = responses,
                CreateRespondViewModel = createResponceViewModel
            };

            return(View("DetailProd", viewModel));
        }
Beispiel #2
0
 public async Task <IActionResult> Respond(RespondViewModel obj)
 {
     if (ModelState.IsValid && obj.Answer.Length == obj.QuestionId.Length)
     {
         Answer[] list = new Answer[obj.Answer.Length];
         for (int x = 0; x < list.Length; x++)
         {
             list[x] = new Answer
             {
                 Date       = DateTime.Now,
                 Lat        = obj.Lat[x],
                 Long       = obj.Long[x],
                 QuestionId = obj.QuestionId[x],
                 Text       = obj.Answer[x]
             };
         }
         try
         {
             await _daoAnswer.AddAll(list);
         }
         catch (DbUpdateConcurrencyException)
         {
             return(Problem());
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(RedirectToAction("Respond", new { id = obj.Quiz }));
 }
Beispiel #3
0
        public ActionResult Respond(RespondViewModel vm)
        {
            if (ModelState.IsValid)
            {
                AdminUser user = this.userTasks.GetAdminUser(User.Identity.Name);

                // update responses
                foreach (ScreeningRequestPersonEntityViewModel rvm in vm.Responses.Values)
                {
                    ScreeningRequestPersonEntity srpe;
                    if (rvm.Id > 0)
                    {
                        srpe = this.screeningTasks.GetScreeningRequestPersonEntity(rvm.Id);
                    }
                    else
                    {
                        srpe = new ScreeningRequestPersonEntity();
                        srpe.ScreeningEntity = user.GetScreeningEntity();
                    }

                    if (srpe.Version > rvm.Version)
                    {
                        ModelState.AddModelError("somekey", "Data has changed since you loaded this page.  Please reload before saving again.  Try pressing the back button to recover your edits.");
                        return(Respond(vm));
                    }

                    srpe.Reason          = rvm.Reason;
                    srpe.Commentary      = rvm.Commentary;
                    srpe.Version         = rvm.Version;
                    srpe.RequestPerson   = this.requestPersonTasks.GetRequestPerson(rvm.RequestPersonID);
                    srpe.ScreeningResult = this.screeningTasks.GetScreeningResult(rvm.ScreeningResultID);
                    this.screeningTasks.SaveOrUpdateScreeningRequestPersonEntity(srpe, User.Identity.Name, ScreeningStatus.UPDATED);
                }
                if (vm.SubmitResponse)
                {
                    ViewBag.SuccessMessage = "Screening request response complete.";

                    // save ScreeningRequestEntityResponse
                    Request request = this.requestTasks.Get(vm.Id);
                    this.screeningTasks.SetEntityResponse(request, user.GetScreeningEntity());

                    // update request history with new status
                    string newStatus = this.screeningTasks.HasAllResponses(request) ? RequestStatus.NAME_SENT_FOR_CONSOLIDATION : RequestStatus.NAME_SCREENING_IN_PROGRESS;
                    this.requestTasks.SaveRequestHistory(vm.Id, this.requestTasks.GetRequestStatus(newStatus).Id, User.Identity.Name);

                    // send email notification
                    this.emailTasks.SendRespondedToEmail(User.Identity.Name, vm.Id);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    // need to start a new transaction in order to refresh srpe.Versions
                    return(RedirectToAction("Respond", new { id = vm.Id }));
                }
            }
            return(Respond(vm.Id));
        }
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value != null)
     {
         if (value.GetType() == typeof(RespondViewModel))
         {
             RespondViewModel vm = (RespondViewModel)value;
             if (vm.SubmitResponse)
             {
                 foreach (ScreeningRequestPersonEntityViewModel srpevm in vm.Responses.Values)
                 {
                     if (srpevm.ScreeningResultID == ScreeningResult.ID_PENDING)  // TODO decouple from hard-coded id numbers
                     {
                         return(new ValidationResult(COLOR_CODING_ERROR_MESSAGE));
                     }
                 }
             }
         }
         else if (value.GetType() == typeof(ConsolidateViewModel))
         {
             ConsolidateViewModel vm = (ConsolidateViewModel)value;
             if (vm.SendForFinalDecision)
             {
                 foreach (RecommendationViewModel rvm in vm.Recommendations.Values)
                 {
                     if (rvm.ScreeningResultID == ScreeningResult.ID_PENDING)
                     {
                         return(new ValidationResult(COLOR_CODING_ERROR_MESSAGE));
                     }
                 }
             }
         }
         else if (value.GetType() == typeof(FinalizeViewModel))
         {
             FinalizeViewModel vm = (FinalizeViewModel)value;
             if (vm.Finalize)
             {
                 foreach (FinalDecisionViewModel fdvm in vm.FinalDecisions.Values)
                 {
                     if (fdvm.ScreeningResultID == ScreeningResult.ID_PENDING)
                     {
                         return(new ValidationResult(COLOR_CODING_ERROR_MESSAGE));
                     }
                     if (fdvm.ScreeningSupportStatusID == ScreeningSupportStatus.ID_PENDING)
                     {
                         return(new ValidationResult(SUPPORT_STATUS_ERROR_MESSAGE));
                     }
                 }
             }
         }
     }
     return(ValidationResult.Success);
 }
Beispiel #5
0
        public IHttpActionResult Post(RespondViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var respond = Mapper.Map <RespondViewModel, RespondTransport>(model);

            RespondManager.CreateRespond(respond);

            return(Ok());
        }
Beispiel #6
0
        public async Task <IActionResult> Post(RespondViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _database.Database.ExecuteSqlCommandAsync("dbo.INSERT_RESPOND @content, @orderId, @executorId",
                                                                new SqlParameter("@content", model.Content),
                                                                new SqlParameter("@executorId", model.ExecutorId),
                                                                new SqlParameter("@orderId", model.OrderId));

                return(Ok(model));
            }

            return(BadRequest());
        }
Beispiel #7
0
        //public async Task<IActionResult> TestCreate()
        //{
        //    var respond = new Respond
        //    {
        //        Name = "1",
        //        Text = "2",
        //        Email = "[email protected]",
        //        ProductId = 2
        //    };
        //    var addedRespond = _context.Add(respond);
        //    await _context.SaveChangesAsync();

        //    return Json(addedRespond);
        //}

        public async Task <IActionResult> Create(RespondViewModel viewModel)
        {
            var respond = new Respond
            {
                Name      = viewModel.Name,
                Text      = viewModel.Text,
                Email     = viewModel.Email,
                ProductId = viewModel.ProductId,
                AddedDate = DateTime.Now
            };

            _context.Add(respond);
            await _context.SaveChangesAsync();

            return(RedirectToAction("DetailProd", "Product", new { id = viewModel.ProductId }));
        }
Beispiel #8
0
        public ActionResult Respond(int id)
        {
            Request request = this.requestTasks.Get(id);

            if (request != null)
            {
                ViewBag.Request          = request;
                ViewBag.User             = this.userTasks.GetAdminUser(User.Identity.Name);
                ViewBag.HasProfileAccess = ((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchPersons);

                // ensure we've persisted ScreeningRequestPersonEntity for every RequestPerson by this stage (its ID is used as param to 'Others' Input' link).
                this.screeningTasks.CreateScreeningRequestPersonEntitiesForRequest(request, ViewBag.User.GetScreeningEntity(), User.Identity.Name);
                RespondViewModel vm = new RespondViewModel(request, this.screeningTasks.GetScreeningResults(request.GetCreatedDate()), ViewBag.User.GetScreeningEntity());

                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
Beispiel #9
0
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value != null)
     {
         if (value.GetType() == typeof(RespondViewModel))
         {
             RespondViewModel vm = (RespondViewModel)value;
             Request          r  = ServiceLocator.Current.GetInstance <IRequestTasks>().Get(vm.Id);
             if (r != null)
             {
                 if (!r.RequiresResponse)
                 {
                     return(new ValidationResult(this.ErrorMessage));
                 }
             }
         }
     }
     return(ValidationResult.Success);
 }
        //  [Authorize(Policy = Constants.Policy.MessageRequirement)]
        public async Task <IActionResult> Correspondence(string id)
        {
            try
            {
                string currentUserId = this.userManager.GetUserId(HttpContext.User);
                var    allMessages   = this.messageService.GetFullCorrespondence(id, currentUserId);

                var messages = allMessages
                               .Select(p =>
                {
                    var model = mapper.Map <Message, MessageViewModel>(p);

                    if (p.ReceiverId == currentUserId)
                    {
                        model.IsReceived = true;
                    }
                    return(model);
                })
                               .ToArray();
                string interlocutor = (await this.userManager.FindByIdAsync(id)).UserName;

                var respondModel = new RespondViewModel
                {
                    RecipientId = id
                };

                var viewModel = new CorrespondenceViewModel
                {
                    Interlocutor = interlocutor,
                    Messages     = messages,
                    Respond      = respondModel
                };

                return(this.View(viewModel));
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.TempData["Error"] = Constants.Message.InvalidOffer;
                return(this.RedirectToAction("Index", "Home"));
            }
        }
 public async Task <IActionResult> Respond(string id, RespondViewModel model)
 {
     if (ModelState.IsValid)
     {
         var message = mapper.Map <RespondViewModel, MessageDTO>(model);
         message.SendDate   = DateTime.Now;
         message.ReceiverId = id;
         message.SenderId   = this.userManager.GetUserId(HttpContext.User);
         try
         {
             var result = await this.messageService.SendMessage(message);
         }
         catch (Exception ex)
         {
             this.TempData[Constants.ValidationState.Error] = ex.Message;
         }
         return(this.RedirectToAction("Correspondence", new { id }));
     }
     else
     {
         return(this.RedirectToAction("Correspondence", new { id }));
     }
 }