Exemple #1
0
        public async Task <IActionResult> Delete(int?id, ComplainCategory complain)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (id != complain.Id)
            {
                return(NotFound());
            }

            var B = _context.ComplainCategories.Find(id);

            if (B == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Remove(B);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(complain));
        }
Exemple #2
0
        public async Task <IActionResult> Update(ComplainCategory complain)
        {
            if (ModelState.IsValid)
            {
                _context.Update(complain);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(complain));
        }
Exemple #3
0
        public async Task <IActionResult> Create(ComplainCategory complain)
        {
            if (ModelState.IsValid)
            {
                var batchexist = _context.ComplainCategories.FirstOrDefault(_ => _.Category == complain.Category);
                if (batchexist != null)
                {
                    ViewBag.message = "Already Exist";
                }

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(complain));
        }
Exemple #4
0
        public IHttpActionResult AddComplain(ComplainDataViewModel complainView)
        {
            try
            {
                string errorMessage = String.Empty;
                Complain complain = new Complain();
                if (complain != null)
                {
                    complain.ID = complainView.id;
                    complain.ComplainNo = String.IsNullOrEmpty(complainView.complainNo) ? String.Empty : complainView.complainNo;
                    complain.BusId = complainView.bus.id;
                    complain.RouteId = complainView.route.id;
                    complain.Place = String.IsNullOrEmpty(complainView.place) ? String.Empty : complainView.place;
                    complain.Date = complainView.complainDate;
                    complain.ComplainStatus = complainView.status;
                    complain.UserId = complainView.userId == 0 ? (int?)null : complainView.userId;
                    if (complainView.memberId != 0) {
                        Member member = _member.GetMember(complainView.memberId);
                        if (member.MemberType.Code == "Driver")
                        {
                            complain.DriverId = member.ID;
                            complain.ConductorId = (int?)null;
                        }
                        else
                        {
                            complain.DriverId = (int?)null;
                            complain.ConductorId = member.ID;
                        }
                    }
                    else
                    {
                        complain.DriverId = _commonData.GetBusById(complainView.bus.id).DriverId;
                        complain.ConductorId = _commonData.GetBusById(complainView.bus.id).ConductorId;
                    }
                    complain.Method = String.IsNullOrEmpty(complainView.method) ? String.Empty : complainView.method;
                    complain.IsInqueryParticipation = complainView.isInqueryParticipation;
                    complain.IsEvidenceHave = complainView.isEvidenceHave;
                    complain.Description = String.IsNullOrEmpty(complainView.description) ? String.Empty : complainView.description;
                    complain.ComplainerName = String.IsNullOrEmpty(complainView.complainerName) ? String.Empty : complainView.complainerName;
                    complain.ComplainerAddress = String.IsNullOrEmpty(complainView.complainerAddress) ? String.Empty : complainView.complainerAddress;
                    complain.ComplainerTel = String.IsNullOrEmpty(complainView.telNo) ? String.Empty : complainView.telNo;

                    complain.ComplainCategories = new List<ComplainCategory>();

                    if (complain.IsEvidenceHave)
                    {
                        complain.Evidence = new Evidence();
                        complain.Evidence.FileName = String.IsNullOrEmpty(complainView.evidence.fileName) ? String.Empty : complainView.evidence.fileName;
                        complain.Evidence.EvidenceNo = complainView.complainNo + complainView.evidence.fileName;
                        complain.Evidence.Extension = String.IsNullOrEmpty(complainView.evidence.extension) ? String.Empty : complainView.evidence.extension;
                        complain.Evidence.FilePath = String.IsNullOrEmpty(complainView.evidence.filePath) ? String.Empty : complainView.evidence.filePath;
                        complain.Evidence.CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]));
                        complain.EvidenceId = complain.Evidence.ID;

                    }

                    foreach (CategoryViewModel complainCategory in complainView.Category)
                    {
                        ComplainCategory category = new ComplainCategory();
                        category.CategoryId = complainCategory.id;
                        category.ComplainId = complain.ID;
                        category.Description = String.IsNullOrEmpty(complainCategory.description)?String.Empty: complainCategory.description;
                        category.IsSelected = complainCategory.isSelected;
                        if (complainCategory.isSelected)
                        {
                            complain.ComplainCategories.Add(category);
                        }
                    }
                    _complain.Add(complain,out errorMessage);
                }
                var messageData = new
                {
                    code = String.IsNullOrEmpty(errorMessage) ? Constant.SuccessMessageCode : Constant.ErrorMessageCode
                   ,
                    message = String.IsNullOrEmpty(errorMessage) ? Constant.MessageSuccess : errorMessage
                };
                var returnObject = new { messageCode = messageData };
                return Ok(returnObject);
            }
            catch (Exception ex)
            {
                string errorLogId = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
                var messageData = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) };
                var returnObject = new { messageCode = messageData };
                return Ok(returnObject);
            }
        }