コード例 #1
0
        public HttpResponseMessage Update(DocTypDTO docTypeDTO)
        {
            try
            {
                int             userID      = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault());
                var             doctyp      = _IOrgdoctypService.GetOrgdoctyp(docTypeDTO.Id);
                MessageTemplate messagetemp = null;

                if (doctyp.Approved != docTypeDTO.Approved)
                {
                    if (docTypeDTO.Approved)
                    {
                        messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "DocTypeAccepted").FirstOrDefault();
                    }
                    else
                    {
                        messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "DocTypeNeedInfo").FirstOrDefault();
                    }
                }

                var user = _IUserService.GetUser(userID);

                if (messagetemp != null)
                {
                    _IMessageuserService.AddMessageuser(new MessageUser()
                    {
                        User = user, DeliveryMethodId = 1, Message = new Message()
                        {
                            CreateDate = DateTime.UtcNow, HeaderText = messagetemp.HeaderText, MessageBody = string.Format(messagetemp.TemplateText, docTypeDTO.Name)
                        }
                    });
                }

                _IOrgdoctypService.UpdateDocType(docTypeDTO, userID);
                _UnitOfWork.Commit();
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(Request.CreateResponse <bool>(HttpStatusCode.OK, true));
        }
コード例 #2
0
        public HttpResponseMessage Create(DocTypDTO docTypeDTO)
        {
            try
            {
                int userID   = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault());
                int statusID = _IDoctypstatusService.GetDoctypstatus().Where(p => p.StatusCd == "INREVIEW").FirstOrDefault().Id;

                var sameNames = _IOrgdoctypService.GetOrgdoctyps().Where(p => p.OrgId == docTypeDTO.OrgId && p.Descript == docTypeDTO.Descript);

                if (sameNames.Count() <= 0)
                {
                    var DocTypWorkflowdef =
                        _IWkflowdefService.GetWkflowdefs().Where(p => p.Code == "DTSW").FirstOrDefault();

                    var wkstatusID = DocTypWorkflowdef.WkflowDefWkflowStats.Where(p => p.WkflowStat.Code == "INREVIEW").FirstOrDefault().WkflowStatId;

                    var messagetemp = _IMessagetemplateService.GetMessagetemplates().Where(p => p.Name == "NewDocTypeSetup").FirstOrDefault();

                    var user = _IUserService.GetUser(userID);

                    // Create a new Document Type Setup workflow
                    var batchWkflowInstance = new WkflowInstance
                    {
                        CreateDate       = DateTime.UtcNow,
                        WkflowDefId      = DocTypWorkflowdef.Id,
                        OrgId            = docTypeDTO.OrgId,
                        User             = user,
                        CurrWkflowStatId = wkstatusID
                    };

                    // Set INIT state for new workflow instance.
                    batchWkflowInstance.WkflowStepHists.Add(new WkflowStepHist
                    {
                        CreateDate    = DateTime.UtcNow,
                        WkflowStatId  = wkstatusID,
                        CreatedUserId = userID
                    });

                    if (messagetemp != null)
                    {
                        _IMessageuserService.AddMessageuser(new MessageUser()
                        {
                            User = user, DeliveryMethodId = 1, Message = new Message()
                            {
                                CreateDate = DateTime.UtcNow, WkflowInstance = batchWkflowInstance, HeaderText = messagetemp.HeaderText, MessageBody = string.Format(messagetemp.TemplateText, docTypeDTO.Name)
                            }
                        });
                    }

                    _IWkflowinstanceService.AddWkflowinstance(batchWkflowInstance);
                    _IOrgdoctypService.CreateNewDocType(docTypeDTO, userID, statusID);
                    _UnitOfWork.Commit();
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "DocType Name Should be Unique"));
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(Request.CreateResponse <bool>(HttpStatusCode.OK, true));
        }