public async Task <ActionResult> Edit(int?id, NewComplaint complaint)
        {
            ViewBag.Error = null;
            List <NewComplaint> complaints = new List <NewComplaint>();

            if (!ModelState.IsValid)
            {
                return(View());
            }
            try
            {
                var response = await client.PutAsJsonAsync(apiBaseUrl + "/Complaint/" + id.ToString(), complaint);

                if (response.IsSuccessStatusCode)
                {
                    ViewData["Message"] = "New Complaint added successfully";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Error = response.Content.ReadAsStringAsync().Result;
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Edit"));
            }
            return(View("Index", complaints));
        }
Пример #2
0
        public ActionResponse Update(int id, NewComplaint updatedComplaint)
        {
            try
            {
                if (updatedComplaint != null)
                {
                    using (var scope = new TransactionScope())
                    {
                        var complaint = unitWork.ComplaintRepository.GetByID(id);
                        if (complaint != null)
                        {
                            unitWork.ComplaintRepository.Update(complaint);
                            unitWork.Save();
                            scope.Complete();
                            response.Success = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Пример #3
0
 // PUT api/Complaint/5
 //Need to modify it as what is actually allowed to update
 public IHttpActionResult Put(int id, [FromBody] NewComplaint complaint)
 {
     complaintService = new ComplaintService();
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     complaintService.Update(id, complaint);
     return(StatusCode(HttpStatusCode.OK));
 }
        public async Task <ActionResult> Create(NewComplaint complaint)
        {
            ViewBag.IsError = false;
            SelectList categories = new SelectList(new List <string>());

            ViewBag.CategoryId   = categories;
            complaint.DistrictId = Convert.ToInt32(System.Web.HttpContext.Current.Session["DistrictId"].ToString());
            complaint.SDCId      = Convert.ToInt32(System.Web.HttpContext.Current.Session["SDCId"].ToString());

            if (!ModelState.IsValid)
            {
                ViewBag.IsError = true;
                return(View(complaint));
            }

            //Check if new complainant
            if (complaint.ComplainantId == 0)
            {
                var complainant = new Complainant()
                {
                    FullName      = complaint.FullName,
                    NIC           = complaint.NIC,
                    Mobile        = complaint.Mobile,
                    Address       = complaint.Address,
                    ContactMedium = Complainant.CommunicationMedium.SMS
                };
                var complainantResponse = await client.PostAsJsonAsync(apiBaseUrl + "/Complainant", complainant);

                if (complainantResponse.IsSuccessStatusCode)
                {
                    var  resultStr     = complainantResponse.Content.ReadAsStringAsync().Result;
                    int  newId         = 0;
                    bool isComplainant = int.TryParse(resultStr, out newId);
                    if (isComplainant)
                    {
                        complaint.ComplainantId = newId;
                    }
                }
            }

            var response = await client.PostAsJsonAsync(apiBaseUrl + "/Complaint", complaint);

            if (response.IsSuccessStatusCode)
            {
                var cId = response.Content.ReadAsStringAsync().Result;
                return(RedirectToAction("Upload", new { id = cId }));
            }

            ViewBag.Error = response.Content.ReadAsStringAsync().Result;
            return(View(complaint));
        }
Пример #5
0
 public complaint AddNewComplaint(NewComplaint newComplaint)
 {
     using (var connection = new SqlConnection(ConnectionString))
     {
         newComplaint.creationDate = DateTime.Now;
         var queryString = @"INSERT into [Activity](userId, creationDate, timeOfDay, zipcode, bitingSource, addtlNotes)
                             Output inserted.*
                             Values(@userId, @creationDate, @timeOfDay, @zipcode, @bitingSource, @addtlNotes)";
         var complaint   = connection.QueryFirstOrDefault <complaint>(queryString, newComplaint);
         if (complaint != null)
         {
             return(complaint);
         }
         throw new Exception("Error, can't add the submission");
     }
 }
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var response = await client.GetAsync(apiBaseUrl + "/Complaint/" + id.ToString());

            NewComplaint complaint = null;

            if (response.IsSuccessStatusCode)
            {
                var data = response.Content.ReadAsStringAsync().Result;
                complaint = JsonConvert.DeserializeObject <NewComplaint>(data);
            }
            SelectList districts = new SelectList(new List <string>());

            ViewBag.DistrictId = districts;
            ViewBag.Title      = "Edit Complaint";
            return(View(complaint));
        }
Пример #7
0
        public IHttpActionResult Post([FromBody] NewComplaint complaint)
        {
            List <string> documents = new List <string>();

            complaintService = new ComplaintService();
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = complaintService.Add(complaint);

            if (response.Success)
            {
                //Create a new directory for the complaint created just now
                string directoryName = "Complaints-" + response.ReturnedId;
                var    mappedPath    = HttpContext.Current.Server.MapPath("~/Uploads/");
                System.IO.Directory.CreateDirectory(mappedPath + directoryName);
                return(Ok(response.ReturnedId));
            }
            return(Content(HttpStatusCode.BadRequest, response.Message));
        }
Пример #8
0
        public ActionResult AddComplaint(NewComplaint newComplaint)
        {
            var createdComplaint = _connections.AddNewComplaint(newComplaint);

            return(Accepted(createdComplaint));
        }
Пример #9
0
        public ActionResult NewComplaint(NewComplaint model)
        {
            try
            {
                ViewBag.ComplaintType = _complaintType.GetAll();
                //ViewBag.SolutionType = _slnType.GetAll();
                //ViewBag.SolutionStatus = _slnStatus.GetAll();
                var user = _user.GetUser(User.Identity.Name);
                ViewBag.Complaints = _vComplaint.FilterComplaint(DateTime.Now.Date, DateTime.Now.Date, 0, 0, 0, user.UserId);

                if (ModelState.IsValid)
                {
                    if (model.Title.Trim().Contains(" "))
                    {
                        ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Empty space is not allowed in Title, you can replace empty space with character like - or _");
                        return(View(model));
                    }
                    if (!string.IsNullOrEmpty(model.ComplaintOwnerEmail))
                    {
                        if (!_help.IsValidEmail(model.ComplaintOwnerEmail))
                        {
                            ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Invalid email address!");
                            return(View(model));
                        }
                    }
                    if (!_help.IsValidPhone(model.MobileNo))
                    {
                        ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Invalid phone number!");
                        return(View(model));
                    }
                    var compType = _complaintType.GetRecordById(model.ComplaintTypeId);
                    model.Title = compType.Name.Replace(" ", "_") + "_" + model.Title + "_" + model.MobileNo;
                    var cmp = _complaint.GetComplaintByTitle(model.Title);
                    if (cmp == null)
                    {
                        var soln = _slnStatus.GetRecordById(1);
                        if (soln.Name.ToUpper() == "RESOLVED FULLY")
                        {
                            model.StatusId = 4;
                        }
                        else
                        {
                            if (soln.Name.ToUpper() == "REQUIRED TECHNICAL SKILL")
                            {
                                model.StatusId = 3;
                            }
                            else
                            {
                                model.StatusId = 2;
                            }
                        }

                        Complaint nc = new Complaint();
                        nc.Code = model.Code;
                        nc.ComplaintOwnerEmail = null;
                        nc.ComplaintOwnerName  = null;
                        nc.ComplaintTypeId     = model.ComplaintTypeId;
                        nc.Date             = DateTime.Now;
                        nc.Details          = model.Details;
                        nc.Location         = model.Location;
                        nc.MobileNo         = model.MobileNo;
                        nc.RegisteredBy     = user.UserId;
                        nc.SolutionStatusId = 1;
                        nc.StatusId         = model.StatusId;
                        nc.Title            = model.Title;

                        using (var cmd = new TransactionScope())
                        {
                            try
                            {
                                _complaint.Create(nc);
                                //ComplaintActivity ca = new ComplaintActivity();
                                //ca.ComplaintId = nc.ComplaintId;
                                //ca.Date = DateTime.Now;
                                //ca.RecordedBy = user.UserId;
                                //ca.SolutionDetails = model.SolutionDetails;
                                //ca.SolutionStatusId = model.SolutionStatusId;
                                //ca.SolutionTypeId = model.SolutionTypeId;
                                //_complaintActivity.Create(ca);
                                cmd.Complete();
                                ViewBag.Msg = _help.getMsg(AlertType.success.ToString(), "Complaint added successful!");
                                return(View(new NewComplaint()));
                            }
                            catch (Exception er)
                            {
                                cmd.Dispose();
                                ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), er.Message);
                                return(View(model));
                            }
                        }
                    }
                    else
                    {
                        ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Complaint title already exist!");
                        return(View(model));
                    }
                }
                else
                {
                    ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "All fields with * are required!");
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), ex.Message);
                return(View(model));
            }
        }
Пример #10
0
        public ActionResponse Add(NewComplaint newComplaint)
        {
            try
            {
                var category = unitWork.CategoryRepository.GetByID(newComplaint.CategoryId);
                if (category == null)
                {
                    response.Message = msgHelper.GetNotFoundMessage("Category");
                    response.Success = false;
                    return(response);
                }

                var district = unitWork.DistrictRepository.GetByID(newComplaint.DistrictId);
                if (district == null)
                {
                    response.Message = msgHelper.GetNotFoundMessage("District");
                    response.Success = false;
                    return(response);
                }

                var sdc = unitWork.SDCRepository.GetByID(newComplaint.SDCId);
                if (sdc == null)
                {
                    response.Message = msgHelper.GetNotFoundMessage("SDC");
                    response.Success = false;
                    return(response);
                }

                var complainant = unitWork.ComplainantRepository.GetByID(newComplaint.ComplainantId);
                if (complainant == null)
                {
                    response.Message = msgHelper.GetNotFoundMessage("Complainant");
                    response.Success = false;
                    return(response);
                }

                using (var scope = new TransactionScope())
                {
                    var complaint = new EFComplaint()
                    {
                        Category    = category,
                        Complainant = complainant,
                        District    = district,
                        SDC         = sdc,
                        Description = newComplaint.Description,
                        Dated       = DateTime.Now,
                        Status      = EFComplaint.ComplaintStatus.InQueue
                    };

                    unitWork.ComplaintRepository.Insert(complaint);
                    //Store references to all the uploaded documents against a complaint

                    /*if (documents.Count > 0)
                     *  {
                     *  List<EFDocuments> docs = new List<EFDocuments>();
                     *  foreach(var docPath in documents)
                     *      {
                     *      docs.Add(new EFDocuments()
                     *      {
                     *          Complaint = complaint,
                     *          Path = docPath
                     *      });
                     *      }
                     *  }*/

                    unitWork.Save();
                    scope.Complete();
                    response.Success    = true;
                    response.ReturnedId = complaint.Id;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }