Exemplo n.º 1
0
        public JsonResult Add(Wiki.Reclamation reclamation, int[] pZ_PlanZakaz)
        {
            string login = HttpContext.User.Identity.Name;

            reclamation.dateTimeCreate = DateTime.Now;
            CreateReclamation correctReclamation = new CreateReclamation(reclamation, login);

            reclamation = correctReclamation.Reclamation;
            db.Reclamation.Add(reclamation);
            db.SaveChanges();
            CreateReclamation_PZ(pZ_PlanZakaz, reclamation.id);
            if (reclamation.technicalAdvice == true)
            {
                CreateTechnicalAdvice(reclamation.id, reclamation.id_AspNetUsersCreate);
            }
            int id_Devision = reclamation.id_DevisionCreate;

            if (id_Devision == 8 || id_Devision == 9 || id_Devision == 10 || id_Devision == 20 || id_Devision == 22)
            {
                if (reclamation.editManufacturing == true)
                {
                    login = db.AspNetUsers.First(d => d.Devision == reclamation.editManufacturingIdDevision && d.ResourceUID != null).Email;
                    try
                    {
                        TaskForPWA pwa = new TaskForPWA();
                        string     reclamationNumAndText = reclamation.id.ToString() + " " + reclamation.text;
                        var        projects = reclamation.Reclamation_PZ.ToList();
                        foreach (var data in projects)
                        {
                            var projectUid = db.PZ_PlanZakaz.Find(data.id_PZ_PlanZakaz).ProjectUID;
                            if (projectUid != null)
                            {
                                pwa.CreateTaskOTK_PO((Guid)projectUid, reclamationNumAndText, login);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            EmailReclamation emailReclamation = new EmailReclamation(reclamation, login, 1);

            return(Json(1, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult Update(Wiki.Reclamation reclamation, int[] pZ_PlanZakaz, string answerText,
                                 bool?reload, int?reloadDevision, bool?trash)
        {
            string      login      = HttpContext.User.Identity.Name;
            AspNetUsers aspNetUser = db.AspNetUsers.First(d => d.Email == login);

            if (aspNetUser.Devision == 6)
            {
                if (reclamation.close == true)
                {
                    string textAnswer = "";
                    textAnswer = "Замечание закрыто ОТК";
                    Reclamation_Answer reclamation_Answer = new Reclamation_Answer
                    {
                        answer               = textAnswer,
                        dateTimeCreate       = DateTime.Now,
                        id_AspNetUsersCreate = aspNetUser.Id,
                        id_Reclamation       = reclamation.id,
                        trash = false
                    };
                    db.Reclamation_Answer.Add(reclamation_Answer);
                    db.SaveChanges();
                }
            }
            CreateReclamation correctPlanZakaz = new CreateReclamation(reclamation, login, reload, reloadDevision);

            reclamation = correctPlanZakaz.Reclamation;
            db.Entry(reclamation).State = EntityState.Modified;
            db.SaveChanges();
            if (aspNetUser.Devision.Value == 6 && answerText != "" && answerText != null)
            {
                Reclamation_Answer reclamation_Answer = new Reclamation_Answer
                {
                    answer               = answerText,
                    dateTimeCreate       = DateTime.Now,
                    id_AspNetUsersCreate = aspNetUser.Id,
                    id_Reclamation       = reclamation.id,
                    trash = trash.Value
                };
                db.Reclamation_Answer.Add(reclamation_Answer);
                db.SaveChanges();
                if (reclamation.close != true)
                {
                    reclamation.closeDevision   = false;
                    db.Entry(reclamation).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else if (aspNetUser.Devision.Value == 28 && answerText != "" && answerText != null)
            {
                Reclamation_Answer reclamation_Answer = new Reclamation_Answer
                {
                    answer               = answerText,
                    dateTimeCreate       = DateTime.Now,
                    id_AspNetUsersCreate = aspNetUser.Id,
                    id_Reclamation       = reclamation.id,
                    trash = trash.Value
                };
                db.Reclamation_Answer.Add(reclamation_Answer);
                db.SaveChanges();
                if (reclamation.close != true)
                {
                    reclamation.closeDevision   = false;
                    db.Entry(reclamation).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else if (aspNetUser.Devision.Value != 6 && aspNetUser.Devision.Value != 28 && answerText != "" && answerText != null)
            {
                Reclamation_Answer reclamation_Answer = new Reclamation_Answer
                {
                    answer               = answerText,
                    dateTimeCreate       = DateTime.Now,
                    id_AspNetUsersCreate = aspNetUser.Id,
                    id_Reclamation       = reclamation.id,
                    trash = trash.Value
                };
                db.Reclamation_Answer.Add(reclamation_Answer);
                db.SaveChanges();
                if (reload != true)
                {
                    if (answerText != "-")
                    {
                        EmailReclamation emailReclamation = new EmailReclamation(reclamation, login, 3);
                    }
                }
            }
            if (reclamation.technicalAdvice == true)
            {
                UpdateTechnicalAdvice(reclamation.id, aspNetUser.Id);
            }
            UpdateReclamation_PZ(pZ_PlanZakaz, reclamation.id);
            if (reload == true)
            {
                Reclamation_Answer reclamation_Answer = new Reclamation_Answer
                {
                    answer               = "Замечание перенаправлено на " + db.Devision.Find(reloadDevision).name,
                    dateTimeCreate       = DateTime.Now,
                    id_AspNetUsersCreate = aspNetUser.Id,
                    id_Reclamation       = reclamation.id,
                    trash = trash.Value
                };
                db.Reclamation_Answer.Add(reclamation_Answer);
                db.SaveChanges();
                EmailReclamation emailReclamation = new EmailReclamation(reclamation, login, 2);
            }



            ReclamationListViewer reclamationListViewer = new ReclamationListViewer();

            reclamationListViewer.GetOneReclamation(reclamation.id);
            return(Json(new { data = reclamationListViewer.ReclamationsListView }));
        }