コード例 #1
0
        public JsonResult <CommonResponse <string> > PostExtendedCardClarification([FromBody] CardClarificationViewModel data)
        {
            var response = new CommonResponse <string>();

            if (!ModelState.IsValid)
            {
                response.InitializeError("");
                return(Json(response));
            }
            var cardId  = data.cardId;
            var content = data.content;

            Document document = context.ObjectContext.GetObject <Document>(cardId); // получил документ

            if (document == null || document?.MainInfo == null)
            {
                response.InitializeError(Resources.Error_OperationIsNotAllowed);
                return(Json(response));
            }

            IStaffService StaffService = context.ObjectContext.GetService <IStaffService>();

            //serviceHelper.StaffService;
            DocumentHelper dh = new DocumentHelper(document, context);
            //отправить задание исполнителю
            List <StaffEmployee> performers = dh.AcquaintanceStaff;

            //var sessionContext = this.serviceHelper.CurrentObjectContextProvider.GetOrCreateCurrentSessionContext();
            DateTime endDate = dh.GetServerDateTime.AddHours(4);

            if (dh.Labourness > 0)
            {
                ICalendarService CalendarService = context.ObjectContext.GetService <ICalendarService>();
                endDate = CalendarService.GetEndDate(new Guid("98E34C46-989A-E211-A503-001676E1723A"), endDate, dh.Labourness);
            }

            //расчет времени исполнения
            try {
                var task = CreateTask(document, new Guid("4BF4A92E-9EFD-432C-B8BA-50B40E0118DB"), performers, endDate, "Задание на исполнение по заявке " + dh.Name, content);
                if (!SentTaskToPerformer(task))
                {
                    response.InitializeError("Задание для не было отправлено");
                    return(Json(response));
                }

                //записать в журнал
                var processStateSection = dh.GetDocument.GetSection(new Guid("0DBB2B16-C311-49B0-9612-647F7C7A7C31")); // содержание
                if (processStateSection.Count > 0)
                {
                    foreach (BaseCardSectionRow row in processStateSection)
                    {
                        var workLabel = row["WorkLabel"].ToString();

                        //Если статус "На диспетчеризации" и дата окончания не NULL
                        if (workLabel.Equals("2") && row["EndDate"] != null)
                        {
                            row["Employee"] = context.ObjectContext.GetObjectRef <StaffEmployee>(StaffService.GetCurrentEmployee()).Id;
                            row["EndDate"]  = dh.GetServerDateTime;

                            DateTime startDate = (DateTime)row["Date"];
                            //if (DateTime.TryParse(row["Date"] as string, out startDate)) {
                            TimeSpan span = dh.GetServerDateTime - startDate;
                            row["Labourness"] = Math.Round(Convert.ToDecimal(span.TotalHours), 2, MidpointRounding.AwayFromZero);
                            //}

                            BaseCardSectionRow newRow = new BaseCardSectionRow();
                            newRow["Date"]      = dh.GetServerDateTime;
                            newRow["WorkLabel"] = 6; //выполняется
                            processStateSection.Add(newRow);
                            context.ObjectContext.SaveObject(document);
                            break;
                        }
                    }
                }

                //изменить состояние карточки
                dh.ChangeStatus("Hold");
            } catch (Exception ex) {
                response.InitializeError(ex.Message);
                return(Json(response));
            }

            response.InitializeSuccess("Задание отправлено на исполнение");
            return(Json(response));
        }