示例#1
0
        public async Task<IHttpActionResult> CreateDocument([FromBody] DocumentBindModel docBind)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var personFrom = await _repPeople.FindAsync(p => p.Id == docBind.PersonFromId);

            if (personFrom == null)
            {
                return BadRequest("Анкета не найдена");
            }

            var userId = User.Identity.GetUserId();
            var now = DateTime.Now;

            var doc = new Document
            {
                CreatedById = userId,
                UpdatedById = userId,
                CreatedDate = now,
                UpdatedDate = now,
                HostPersonId = personFrom.Id,
                Type = (DocumentType)docBind.Type
            };

            if (docBind.Type == DocumentType.MigrationRegistration)
            {
                var personTo = _repPeople.Find(p => p.Id == docBind.PersonToId);
                if (personTo == null)
                {
                    return BadRequest("Анкета не найдена");
                }
                if (personTo.Type == PersonType.Host && personFrom.Type == PersonType.Host)
                {
                    return BadRequest("Принимающей стороне невозможно добавить принимающую сторону");
                }
                doc.ApplicantPersonId = personTo.Id;
            }

            _repDocs.Add(doc);

            return Ok(doc);
        }
示例#2
0
        private DocumentParameter GetOrCreateDocumentParameter(bool shouldSave, Document doc, PrmFactName paramName, string strValue = null, int? intValue = null, float? floatValue = null, DateTime? dateValue = null)
        {
            strValue = strValue ?? string.Empty;

            var docPrm = _db.DocumentParameters.SingleOrDefault(d => d.DocumentId == doc.Id && d.ParameterId == paramName.Id);
            if (docPrm == null)
            {
                docPrm = new DocumentParameter()
                {
                    DateValue = dateValue,
                    IntValue = intValue,
                    FloatValue = floatValue,
                    StringValue = strValue,
                    DocumentId = doc.Id,
                    ParameterId = paramName.Id
                };
                _db.DocumentParameters.Add(docPrm);
            }
            else
            {
                docPrm.DateValue = dateValue;
                docPrm.IntValue = intValue;
                docPrm.FloatValue = floatValue;
                docPrm.StringValue = strValue;
                docPrm.DocumentId = doc.Id;
                docPrm.ParameterId = paramName.Id;
            }

            if (shouldSave)
            {
                _db.SaveChanges();
            }
            return docPrm;
        }
示例#3
0
 private Document GetOrCreateDocument(Person person, DocumentType type, string number, string userid)
 {
     var doc = _db.Documents.SingleOrDefault(d => d.Number == number && d.Type == type);
     if (doc == null)
     {
         var now = DateTime.Now;
         doc = new Document()
         {
             ApplicantPersonId = (person.Type == PersonType.Applicant) ? person.Id : (int?)null,
             HostPersonId = (person.Type == PersonType.Host) ? person.Id : (int?)null,
             Number = number,
             CreatedById = userid,
             UpdatedById = userid,
             CreatedDate = now,
             UpdatedDate = now,
             Type = type
         };
         _db.Documents.Add(doc);
         _db.SaveChanges();
     }
     return doc;
 }
示例#4
0
        private void UpdateDocumentParams(Document doc, IList<ParameterViewModel> parameters)
        {
            var names = _repParamNames.FindAll(d => d.Category == ParameterCategory.Document && d.DocType == doc.Type && d.IsFact == false).ToDictionary(k => k.Name, v => v);
            var docParams = _repDocParams.FindAll(d => d.DocumentId == doc.Id).ToDictionary(k => k.ParameterId, v => v);

            var list = new List<DocumentParameter>();
            foreach (var prm in parameters)
            {
                var pn = names[prm.Name];

                DocumentParameter docParam = null;
                if (docParams.ContainsKey(pn.Id))
                {
                    docParam = docParams[pn.Id];
                    docParam.DateValue = prm.DateValue;
                    docParam.FloatValue = prm.FloatValue;
                    docParam.IntValue = prm.MiscId;
                    docParam.StringValue = prm.StringValue;
                }
                else
                {
                    docParam = new DocumentParameter
                    {
                        ParameterId = pn.Id,
                        DocumentId = doc.Id,
                        DateValue = prm.DateValue,
                        FloatValue = prm.FloatValue,
                        IntValue = prm.MiscId,
                        StringValue = prm.StringValue
                    };
                }

                list.Add(docParam);
            };

            _repDocParams.AddRange(list.Where(p => p.Id == 0).AsEnumerable());
            _repDocParams.UpdateRange(list.Where(p => p.Id != 0).AsEnumerable());
        }
示例#5
0
        private DocumentParameter UpdateOrCreateDocumentParameter(Document doc, ParameterName paramName, string strValue = null, int? intValue = null, float? floatValue = null, DateTime? dateValue = null)
        {
            strValue = NormalizeString(strValue, true);

            var docPrm = _db.DocumentParameters.SingleOrDefault(d => d.DocumentId == doc.Id && d.ParameterId == paramName.Id);
            if (docPrm == null)
            {
                docPrm = new DocumentParameter()
                {
                    DateValue = dateValue,
                    IntValue = intValue,
                    FloatValue = floatValue,
                    StringValue = strValue,
                    DocumentId = doc.Id,
                    ParameterId = paramName.Id
                };
                _db.DocumentParameters.Add(docPrm);
            }
            else
            {
                docPrm.DateValue = dateValue;
                docPrm.IntValue = intValue;
                docPrm.FloatValue = floatValue;
                docPrm.StringValue = strValue;
                docPrm.DocumentId = doc.Id;
                docPrm.ParameterId = paramName.Id;
            };

            _db.SaveChanges();
            return docPrm;
        }
示例#6
0
        private Document UpdateOrCreateDocumentByApplicantDateNumber(Person person, DocumentType type, DateTime date, string number, string userid)
        {
            number = NormalizeString(number, false);

            var doc = _db.Documents.SingleOrDefault(d => d.CreatedDate == date && d.Number == number && d.ApplicantPersonId == person.Id && d.Type == type);
            if (doc == null)
            {
                doc = new Document()
                {
                    ApplicantPersonId = person.Id,
                    HostPersonId = null,
                    Number = number,
                    CreatedById = userid,
                    UpdatedById = userid,
                    CreatedDate = date,
                    UpdatedDate = DateTime.Now,
                    Type = type
                };
                _db.Documents.Add(doc);
                _db.SaveChanges();
            }
            return doc;
        }
示例#7
0
        private Document UpdateOrCreateDocumentByNumber(Person applicant, Person host, DocumentType type, string number, string userid)
        {
            number = NormalizeString(number, false);

            var doc = _db.Documents.SingleOrDefault(d => d.Number == number && d.Type == type);
            if (doc == null)
            {
                var now = DateTime.Now;
                doc = new Document()
                {
                    ApplicantPersonId = applicant.Id,
                    HostPersonId = host.Id,
                    Number = number,
                    CreatedById = userid,
                    UpdatedById = userid,
                    CreatedDate = now,
                    UpdatedDate = now,
                    Type = type
                };
                _db.Documents.Add(doc);
                _db.SaveChanges();
            }
            return doc;
        }