public ActionResult CreateInvoice(FailureViewModel model)
        {
            try
            {
                var failure = _failureRepo.GetById(model.FailureId);
                if (model.HasWarranty)
                {
                    failure.Price = 0m;
                }
                else
                {
                    failure.Price = model.Price;
                }
                failure.HasWarranty   = model.HasWarranty;
                failure.Report        = model.Report;
                failure.RepairProcess = model.RepairProcess;
                _failureRepo.Update(failure);
                TempData["Message"] = $"{model.FailureId} no lu arıza için tutar girilmiştir.";

                //var survey = new SurveyRepo().GetById(model.FailureId);
                var survey = new Survey();
                _surveyRepo.Insert(survey);
                failure.SurveyId = survey.Id;
                _surveyRepo.Update(survey);

                var user = _membershipTools.UserManager.FindByIdAsync(failure.ClientId).Result;
                var clientNameSurname = _membershipTools.GetNameSurname(failure.ClientId);

                var uri = new UriBuilder()
                {
                    Scheme = Uri.UriSchemeHttps
                };
                var    hostComponents = Request.Host.ToUriComponent();
                string siteUrl        = uri.Scheme + System.Uri.SchemeDelimiter + hostComponents;

                EmailService emailService = new EmailService();
                var          body         = $"Merhaba <b>{clientNameSurname.Result}</b><br>{failure.Description} adlı arıza kaydınız kapanmıştır.<br>Değerlendirmeniz için aşağıda linki bulunan anketi doldurmanızı rica ederiz.<br> <a href='{siteUrl}/failure/survey?code={failure.SurveyId}' >Anket Linki </a> ";
                emailService.Send(new EmailModel()
                {
                    Body = body, Subject = "Değerlendirme Anketi"
                }, user.Email);

                return(RedirectToAction("Detail", "Technician", new
                {
                    id = model.FailureId
                }));
            }
            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "CreateInvoice",
                    ControllerName = "Technician",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 2
0
        public ActionResult CreateInvoice(FailureViewModel model)
        {
            try
            {
                var failure = new FailureRepo().GetById(model.FailureId);
                if (model.HasWarranty)
                {
                    failure.Price = 0m;
                }
                else
                {
                    failure.Price = model.Price;
                }
                failure.HasWarranty   = model.HasWarranty;
                failure.Report        = model.Report;
                failure.RepairProcess = model.RepairProcess;
                new FailureRepo().Update(failure);
                TempData["Message"] = $"{model.FailureId} no lu arıza için tutar girilmiştir.";

                //var survey = new SurveyRepo().GetById(model.FailureId);
                var survey     = new Survey();
                var surveyRepo = new SurveyRepo();
                surveyRepo.Insert(survey);
                failure.SurveyId = survey.Id;
                surveyRepo.Update(survey);

                var user = NewUserManager().FindById(failure.ClientId);
                var clientNameSurname = GetNameSurname(failure.ClientId);

                string siteUrl = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host +
                                 (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port);



                var emailService = new EmailService();
                var body         = $"Merhaba <b>{clientNameSurname}</b><br>{failure.Description} adlı arıza kaydınız kapanmıştır.<br>Değerlendirmeniz için aşağıda linki bulunan anketi doldurmanızı rica ederiz.<br> <a href='{siteUrl}/failure/survey?code={failure.SurveyId}' >Anket Linki </a> ";
                emailService.Send(new IdentityMessage()
                {
                    Body = body, Subject = "Değerlendirme Anketi"
                }, user.Email);

                return(RedirectToAction("Detail", "Technician", new
                {
                    id = model.FailureId
                }));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "Detail",
                    ControllerName = "Operator",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Decline(FailureViewModel model)
        {
            try
            {
                var failure = _failureRepo.GetById(model.FailureId);
                if (failure.OperationStatus == OperationStatuses.Declined)
                {
                    TempData["Message"] =
                        $"{failure.Id} nolu arıza zaten reddedilmiştir.";
                    return(RedirectToAction("Detail", "Operator", new { id = model.FailureId }));
                }

                failure.OperationStatus = OperationStatuses.Declined;
                failure.OperationTime   = DateTime.Now;
                failure.OperatorId      = _membershipTools.UserManager.GetUserAsync(HttpContext.User).Result.Id;
                failure.Report          = model.Report;
                _failureRepo.Update(failure);
                _failureLogRepo.Insert(new FailureLog()
                {
                    FailureId = failure.Id,
                    Message   = $"Arızanız şu nedenden dolayı reddedilmiştir: {failure.Report}",
                    FromWhom  = IdentityRoles.Operator
                });

                TempData["Message"] =
                    $"{failure.Id} nolu arıza reddedilmiştir.";

                var emailService = new EmailService();
                var body         =
                    $"Merhaba <b>{failure.Client.Name} {failure.Client.Surname}</b><br>{failure.FailureName} adlı arızanız şu nedenden dolayı reddedilmiştir:<br><br>{failure.Report}<br><br>İyi günler dileriz.";
                await emailService.SendAsync(new EmailModel()
                {
                    Body    = body,
                    Subject = $"{failure.FailureName} adlı arızanız reddedilmiştir. | Teknik Servisçi"
                }, failure.Client.Email);

                return(RedirectToAction("Detail", "Operator", new { id = model.FailureId }));
            }


            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Decline",
                    ControllerName = "Operator",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult> TechnicianAdd(FailureViewModel model)
        {
            try
            {
                var failure = new FailureRepo().GetById(model.FailureId);
                failure.TechnicianId    = model.TechnicianId;
                failure.OperationTime   = DateTime.Now;
                failure.OperatorId      = System.Web.HttpContext.Current.User.Identity.GetUserId();
                failure.OperationStatus = OperationStatuses.Accepted;
                new FailureRepo().Update(failure);
                var technician = await NewUserStore().FindByIdAsync(failure.TechnicianId);

                TempData["Message"] =
                    $"{failure.Id} nolu arızaya {technician.Name}  {technician.Surname} atanmıştır.İyi çalışmalar.";

                new OperationRepo().Insert(new Operation()
                {
                    FailureId = model.FailureId,
                    Message   = $"Arızaya yeni teknisyen atanmıştır: {technician.Name} {technician.Surname}",
                    FromWhom  = IdentityRoles.Operator
                });

                var emailService = new EmailService();
                var body         = $"Merhaba <b>{failure.Client.Name} {failure.Client.Surname}</b><br>{failure.FailureName} adlı arızanız onaylanmış ve alanında uzman teknisyenlerimizden birine atanmıştır. Sizinle yeniden iletişime geçilecektir.<br><br>İyi günler dileriz.";
                await emailService.SendAsync(new IdentityMessage()
                {
                    Body    = body,
                    Subject = $"{failure.FailureName} adlı arızanız onaylanmıştır. | Teknik Servisçi"
                }, failure.Client.Email);

                return(RedirectToAction("Detail", "Operator", new { id = model.FailureId }));
            }

            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "TechnicianAdd",
                    ControllerName = "Operator",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult> TechnicianAdd(FailureViewModel model)
        {
            try
            {
                var failure = _failureRepo.GetById(model.FailureId);
                failure.TechnicianId    = model.TechnicianId;
                failure.OperationTime   = DateTime.Now;
                failure.OperatorId      = _membershipTools.UserManager.GetUserAsync(HttpContext.User).Result.Id;
                failure.OperationStatus = OperationStatuses.Accepted;
                _failureRepo.Update(failure);
                var technician = _membershipTools.UserManager.FindByIdAsync(failure.TechnicianId).Result;
                TempData["Message"] =
                    $"{failure.Id} nolu arızaya {technician.Name} {technician.Surname} atanmıştır.İyi çalışmalar.";

                _failureLogRepo.Insert(new FailureLog()
                {
                    FailureId = model.FailureId,
                    Message   = $"Arızaya yeni teknisyen atanmıştır: {technician.Name} {technician.Surname}",
                    FromWhom  = IdentityRoles.Operator
                });

                var emailService = new EmailService();
                var body         = $"Merhaba <b>{_membershipTools.GetNameSurname(failure.ClientId).Result}</b><br>{failure.FailureName} adlı arızanız onaylanmış ve alanında uzman teknisyenlerimizden birine atanmıştır. Sizinle yeniden iletişime geçilecektir.<br><br>İyi günler dileriz.";
                await emailService.SendAsync(new EmailModel()
                {
                    Body    = body,
                    Subject = $"{failure.FailureName} adlı arızanız onaylanmıştır. | Teknik Servisçi"
                }, failure.Client.Email);

                return(RedirectToAction("Detail", "Operator", new { id = model.FailureId }));
            }

            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "TechnicianAdd",
                    ControllerName = "Operator",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 6
0
        private FailureView CreateFailureView(InvoiceErrorDetails errorDetails)
        {
            FailureView failureView = new FailureView();

            FailureViewModel failureVM = new FailureViewModel();

            failureVM.HeaderText   = errorDetails.Header;
            failureVM.FailureTitle = IsDisallow(errorDetails.PageType)
                ? Constants.DisallowHeader
                : IsWarning(errorDetails.PageType) ? Constants.WarningHeader
                                 : "Failed (" + GetFailedCount(errorDetails.ErrorDetails) + ")";
            failureVM.ApproveErrorItems = GetApproveErrorItems(errorDetails.ErrorDetails);
            failureVM.InvoiceList       = errorDetails.InvoiceBasicDetails;
            failureVM.InitializeCommands(IsWarning(errorDetails.PageType));

            failureView.DataContext = failureVM;

            failureView.Height = 0.6 * Window.Current.CoreWindow.Bounds.Bottom;
            failureView.Width  = 0.5 * Window.Current.CoreWindow.Bounds.Right;

            return(failureView);
        }
Exemplo n.º 7
0
        public async Task <ActionResult> TechnicianStartWork(FailureViewModel model)
        {
            try
            {
                var failure = await new FailureRepo().GetByIdAsync(model.FailureId);

                switch (failure.Technician.TechnicianStatus)
                {
                case TechnicianStatuses.Available:
                    model.TechnicianStatus = TechnicianStatuses.OnWay;
                    new OperationRepo().Insert(new Operation()
                    {
                        FailureId = model.FailureId,
                        Message   = "Teknisyen yola çıktı.",
                        FromWhom  = IdentityRoles.Technician
                    });
                    //todo: Kullanıcıya mail gitsin.
                    break;

                case TechnicianStatuses.OnWay:
                    failure.StartingTime   = DateTime.Now;
                    model.TechnicianStatus = TechnicianStatuses.OnWork;
                    new OperationRepo().Insert(new Operation()
                    {
                        FailureId = model.FailureId,
                        Message   = "Teknisyen işe başladı.",
                        FromWhom  = IdentityRoles.Technician
                    });
                    break;

                case TechnicianStatuses.OnWork:
                    model.TechnicianStatus = TechnicianStatuses.Available;
                    failure.FinishingTime  = DateTime.Now;
                    new OperationRepo().Insert(new Operation()
                    {
                        FailureId = model.FailureId,
                        Message   = "İş tamamlandı.",
                        FromWhom  = IdentityRoles.Technician
                    });
                    return(RedirectToAction("CreateInvoice", "Technician", new
                    {
                        id = model.FailureId
                    }));

                default:
                    break;
                }

                failure.Report = model.Report;
                failure.Technician.TechnicianStatus = model.TechnicianStatus;
                if (model.RepairProcess == RepairProcesses.Successful)
                {
                    failure.FinishingTime = DateTime.Now;
                }
                else if (model.RepairProcess == RepairProcesses.Failed)
                {
                    failure.FinishingTime = DateTime.Now;
                }


                new FailureRepo().Update(failure);

                TempData["Message"] = $"{model.FailureId} no lu arıza için yola çıkılmıştır";
                return(RedirectToAction("Detail", "Technician", new
                {
                    id = model.FailureId
                }));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "TechnicianStartWork",
                    ControllerName = "Technician",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Add(FailureViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                model.ClientId = _membershipTools.UserManager.GetUserAsync(HttpContext.User).Result.Id;

                var data = _mapper.Map <FailureViewModel, Failure>(model);

                _failureRepo.Insert(data);

                _failureLogRepo.Insert(new FailureLog()
                {
                    FailureId = data.Id,
                    Message   = $"#{data.Id} - {data.FailureName} adlı arıza kaydı oluşturuldu.",
                    FromWhom  = IdentityRoles.Client
                });

                if (model.PostedFile != null && model.PostedFile.Count > 0)
                {
                    foreach (var file in model.PostedFile)
                    {
                        if (file == null || file.Length <= 0)
                        {
                            return(null);
                        }

                        string fileName = "failure-" + Path.GetFileNameWithoutExtension(file.FileName);
                        string extName  = Path.GetExtension(file.FileName);
                        fileName  = StringHelpers.UrlFormatConverter(fileName);
                        fileName += StringHelpers.GetCode();

                        var webpath       = _hostingEnvironment.WebRootPath;
                        var directorypath = Path.Combine(webpath, "Uploads/Failure");
                        var filePath      = Path.Combine(directorypath, fileName + extName);

                        if (!Directory.Exists(directorypath))
                        {
                            Directory.CreateDirectory(directorypath);
                        }

                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }

                        _photoRepo.Insert(new Photo()
                        {
                            FailureId = data.Id,
                            Path      = "/Uploads/Failure/" + fileName + extName
                        });
                    }
                }
                await _dbContext.SaveChangesAsync();

                var photos = _photoRepo.GetAll(x => x.FailureId == data.Id).ToList();
                var photo  = photos.Select(x => x.Path).ToList();
                data.PhotoPath = photo;
                _failureRepo.Update(data);

                await _dbContext.SaveChangesAsync();

                TempData["Message"] = $"{model.FailureName} adlı arızanız operatörlerimizce incelenecektir ve size 24 saat içinde dönüş yapılacaktır.";
                return(RedirectToAction("Add"));
            }
            //catch (DbEntityValidationException ex)
            //{
            //    TempData["Model"] = new ErrorViewModel()
            //    {
            //        Text = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
            //        ActionName = "Add",
            //        ControllerName = "Failure",
            //        ErrorCode = 500
            //    };
            //    return RedirectToAction("Error", "Home");
            //}
            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Add",
                    ControllerName = "Failure",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
        public IActionResult TechnicianStartWork(FailureViewModel model)
        {
            try
            {
                var failure = _failureRepo.GetById(model.FailureId);
                failure.Technician = _membershipTools.UserManager.FindByIdAsync(failure.TechnicianId).Result;
                switch (failure.Technician.TechnicianStatus)
                {
                case TechnicianStatuses.Available:
                    model.TechnicianStatus = TechnicianStatuses.OnWay;
                    _failureLogRepo.Insert(new FailureLog()
                    {
                        FailureId = model.FailureId,
                        Message   = "Teknisyen yola çıktı.",
                        FromWhom  = IdentityRoles.Technician
                    });
                    //todo: Kullanıcıya mail gitsin.
                    break;

                case TechnicianStatuses.OnWay:
                    failure.StartingTime   = DateTime.Now;
                    model.TechnicianStatus = TechnicianStatuses.OnWork;
                    _failureLogRepo.Insert(new FailureLog()
                    {
                        FailureId = model.FailureId,
                        Message   = "Teknisyen işe başladı.",
                        FromWhom  = IdentityRoles.Technician
                    });
                    break;

                case TechnicianStatuses.OnWork:
                    model.TechnicianStatus = TechnicianStatuses.Available;
                    failure.FinishingTime  = DateTime.Now;
                    _failureLogRepo.Insert(new FailureLog()
                    {
                        FailureId = model.FailureId,
                        Message   = "İş tamamlandı.",
                        FromWhom  = IdentityRoles.Technician
                    });
                    return(RedirectToAction("CreateInvoice", "Technician", new
                    {
                        id = model.FailureId
                    }));

                default:
                    break;
                }

                failure.Report = model.Report;
                failure.Technician.TechnicianStatus = model.TechnicianStatus;
                if (model.RepairProcess == RepairProcesses.Successful)
                {
                    failure.FinishingTime = DateTime.Now;
                }
                else if (model.RepairProcess == RepairProcesses.Failed)
                {
                    failure.FinishingTime = DateTime.Now;
                }

                _failureRepo.Update(failure);

                TempData["Message"] = $"{model.FailureId} no lu arıza için yola çıkılmıştır";
                return(RedirectToAction("Detail", "Technician", new
                {
                    id = model.FailureId
                }));
            }
            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "TechnicianStartWork",
                    ControllerName = "Technician",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 10
0
        public ActionResult Add(FailureViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                model.ClientId = System.Web.HttpContext.Current.User.Identity.GetUserId();

                var data = Mapper.Map <FailureViewModel, Failure>(model);

                var failureRepo = new FailureRepo();
                failureRepo.Insert(data);
                var photoRepo = new PhotoRepo();
                if (model.PostedPhoto.Count > 0)
                {
                    model.PostedPhoto.ForEach(file =>
                    {
                        if (file == null || file.ContentLength <= 0)
                        {
                            return;
                        }

                        string fileName = "failure-";
                        fileName       += Path.GetFileNameWithoutExtension(file.FileName);
                        string extName  = Path.GetExtension(file.FileName);
                        fileName        = StringHelpers.UrlFormatConverter(fileName);
                        fileName       += StringHelpers.GetCode();
                        var klasoryolu  = Server.MapPath("~/Upload/Failure/");
                        var dosyayolu   = Server.MapPath("~/Upload/Failure/") + fileName + extName;

                        if (!Directory.Exists(klasoryolu))
                        {
                            Directory.CreateDirectory(klasoryolu);
                        }
                        file.SaveAs(dosyayolu);

                        WebImage img = new WebImage(dosyayolu);
                        img.Resize(800, 600, false);
                        img.AddTextWatermark("Teknik Servisçi");
                        img.Save(dosyayolu);
                        photoRepo.Insert(new Photo()
                        {
                            FailureId = data.Id,
                            Path      = "/Upload/Failure/" + fileName + extName
                        });
                    });
                }

                var photos = photoRepo.GetAll(x => x.FailureId == data.Id).ToList();
                var photo  = photos.Select(x => x.Path).ToList();
                data.PhotoPath = photo;
                failureRepo.Update(data);

                new OperationRepo().Insert(new Operation()
                {
                    FailureId = data.Id,
                    Message   = $"#{data.Id} - {data.FailureName} adlı arıza kaydı oluşturuldu.",
                    FromWhom  = IdentityRoles.User
                });
                TempData["Message"] = $"{model.FailureName} adlı arızanız operatörlerimizce incelenecektir ve size 24 saat içinde dönüş yapılacaktır.";
                return(RedirectToAction("Add"));
            }
            catch (DbEntityValidationException ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
                    ActionName     = "Add",
                    ControllerName = "Failure",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Add",
                    ControllerName = "Failure",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }