示例#1
0
        public ActionResult NewDocument(FormCollection formValues)
        {
            Guid userGuid = AppContext.GetUserGuid();

            if (userGuid == Guid.Empty)
            {
                return(new HttpUnauthorizedResult());
            }
            Guid documentID = _repository.CreateDocument(userGuid);

            InfoTypeOne infoTypeOne = new InfoTypeOne()
            {
                DocumentID = documentID
            };
            InfoTypeTwo infoTypeTwo = new InfoTypeTwo()
            {
                DocumentID = documentID
            };

            if (AppContext.AllowInfoTypeOneWrite())
            {
                UpdateModel <InfoTypeOne>(infoTypeOne);
            }

            if (AppContext.AllowInfoTypeTwoWrite())
            {
                UpdateModel <InfoTypeTwo>(infoTypeTwo);
            }

            if (AppContext.AllowScansWrite())
            {
                string[]    scansGuids = formValues["selectedScans"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                List <Guid> guidsList  = new List <Guid>();
                foreach (var guid in scansGuids)
                {
                    guidsList.Add(new Guid(guid));
                }
                _repository.SetDocumentScans(guidsList, documentID);
            }

            string[] senderIDs = formValues["sendersIDs"].Split(',');
            foreach (string sid in senderIDs)
            {
                int tmp;
                if (!int.TryParse(sid, out tmp))
                {
                    continue;
                }
                _repository.AddSender(documentID, tmp);
            }

            //poza ifami poniewa¿ i tak tworzymy "wydmuszki" sekcji
            _repository.CreateInfoTypeOne(infoTypeOne);
            _repository.CreateInfoTypeTwo(infoTypeTwo);

            _repository.SubmitChanges();
            return(RedirectToAction("Index", "Scans", new { documentID = documentID }));
        }
示例#2
0
        public ActionResult Edit(Guid documentID, string selectedScans, string DocumentNumber, string CaseNumber,
                                 DateTime?Date, int?CategoryID, int?TypeID, string sendersIDs, string Description, string Submit, int?Type2ID, string Tags, bool?Flag1)
        {
            if (Submit.Equals("Zapisz"))
            {
                DocumentDetails details  = _repository.GetDocumentDetails(documentID);
                Document        document = _repository.GetDocument(documentID);

                if (AppContext.AllowScansWrite())
                {
                    ScansRepository scansRepository = new ScansRepository();

                    #region Add/Remove scans
                    List <Guid> scansIDs      = new List <Guid>();
                    List <Guid> scansToAdd    = new List <Guid>();
                    List <Guid> scansToRemove = new List <Guid>();

                    foreach (string g in selectedScans.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        Guid guid;
                        try
                        {
                            guid = new Guid(g);
                            if (!details.ScanIDs.Contains(guid))
                            {
                                scansToAdd.Add(guid);
                            }
                        }
                        catch (FormatException)
                        {
                            break;
                        }
                        scansIDs.Add(guid);
                    }

                    foreach (Guid guid in details.ScanIDs)
                    {
                        if (!scansIDs.Contains(guid))
                        {
                            scansToRemove.Add(guid);
                        }
                    }

                    _repository.SetDocumentScans(scansToAdd, documentID);
                    _repository.RemoveDocumentScans(scansToRemove);
                    #endregion
                }

                if (AppContext.AllowInfoTypeOneWrite())
                {
                    details.InfoTypeOne.DocumentNumber = DocumentNumber;
                    details.InfoTypeOne.CaseNumber     = CaseNumber;
                    details.InfoTypeOne.Date           = Date;
                    details.InfoTypeOne.CategoryID     = CategoryID;
                    details.InfoTypeOne.TypeID         = TypeID;
                    details.InfoTypeOne.Type2ID        = Type2ID;
                    details.InfoTypeOne.Tags           = Tags;
                }

                if (AppContext.AllowInfoTypeTwoWrite())
                {
                    string[] senderIDs = sendersIDs.Split(',');
                    _repository.RemoveSenders(documentID);
                    foreach (string sid in senderIDs)
                    {
                        int tmp;
                        if (!int.TryParse(sid, out tmp))
                        {
                            continue;
                        }
                        _repository.AddSender(documentID, tmp);
                    }

                    details.InfoTypeTwo.Description = Description;
                    details.InfoTypeTwo.Flag1       = Flag1 ?? false;
                }

                document.Editor = AppContext.GetUserGuid();

                _repository.SubmitChanges();
            }

            return(RedirectToAction("Details", new { documentID = documentID }));
        }