Example #1
0
        public Guid InsertSource(SourceDto sourceAjaxDto)
        {
            var source = new Source
            {
                SourceDescription = sourceAjaxDto.SourceDesc,
                OriginalLocation = sourceAjaxDto.OriginalLocation,
                IsCopyHeld = sourceAjaxDto.IsCopyHeld,
                IsViewed = sourceAjaxDto.IsViewed,
                IsThackrayFound = sourceAjaxDto.IsThackrayFound,
                UserId = 0,
                SourceDate = sourceAjaxDto.SourceDateStr.ParseToValidYear(),
                SourceDateTo = sourceAjaxDto.SourceDateStrTo.ParseToValidYear(),
                SourceDateStr = sourceAjaxDto.SourceDateStr,
                SourceDateStrTo = sourceAjaxDto.SourceDateStrTo,
                SourceRef = sourceAjaxDto.SourceRef,
                SourceFileCount = sourceAjaxDto.SourceFileCount,
                SourceNotes = sourceAjaxDto.SourceNotes,
                SourceId = (sourceAjaxDto.SourceId == Guid.Empty ? Guid.NewGuid() : sourceAjaxDto.SourceId ),
                VirtualLocation = sourceAjaxDto.VirtualLocation,
                DateAdded = DateTime.Today
            };

            using (var context = new GeneralModelContainer())
            {

                context.Sources.Add(source);

                context.SaveChanges();
            }

            return source.SourceId;
        }
Example #2
0
        public void UpdateSource(SourceDto sourceAjaxDto)
        {
            using (var context = new GeneralModelContainer())
            {
                var source = context.Sources.FirstOrDefault(o => o.SourceId == sourceAjaxDto.SourceId);

                if (source == null) return;

                source.SourceDescription = sourceAjaxDto.SourceDesc;
                source.OriginalLocation = sourceAjaxDto.OriginalLocation;
                source.IsCopyHeld = sourceAjaxDto.IsCopyHeld;
                source.IsViewed = sourceAjaxDto.IsViewed;
                source.IsThackrayFound = sourceAjaxDto.IsThackrayFound;
                source.UserId = 1;
                source.SourceDate = sourceAjaxDto.SourceDateStr.ParseToValidYear();
                source.SourceDateTo = sourceAjaxDto.SourceDateStrTo.ParseToValidYear();
                source.SourceDateStr = sourceAjaxDto.SourceDateStr;
                source.SourceDateStrTo = sourceAjaxDto.SourceDateStrTo;
                source.SourceRef = sourceAjaxDto.SourceRef;
                source.SourceFileCount = sourceAjaxDto.SourceFileCount;
                source.SourceNotes = sourceAjaxDto.SourceNotes;
                source.VirtualLocation = (!string.IsNullOrEmpty(sourceAjaxDto.VirtualLocation)
                    ? sourceAjaxDto.VirtualLocation
                    : source.VirtualLocation); // dont overwrite this unless we have a value
                source.DateAdded = DateTime.Today;

                context.SaveChanges();
            }
        }
        public string AddSource(string sourceId,
                                   string isCopyHeld,
                                   string isThackrayFound,
                                   string isViewed,
                                   string originalLocation,
                                   string sourceDesc,
                                   string sourceRef,
                                   string sourceNotes,
                                   string sourceDateStr,
                                   string sourceDateStrTo,
                                   string sourceFileCount,
                                   string parishs,
                                   string sourceTypes,
                                   string fileIds)
        {
            string retVal = "";

            var jss = new JavaScriptSerializer();

            var obj = jss.Deserialize<dynamic>(fileIds);

            var tp = new List<ServiceFile>();

            if (obj != null)
                foreach (dynamic item in obj)
                    tp.Add(new ServiceFile(item["url"],item["desc"],item["id"]));

            var ssobj = new SourceDto()
                {
                    IsCopyHeld = isCopyHeld.ToBool(),
                    IsThackrayFound = isThackrayFound.ToBool(),
                    IsViewed = isViewed.ToBool(),
                    OriginalLocation = originalLocation,
                    SourceDateStr = sourceDateStr,
                    SourceDateStrTo = sourceDateStrTo,
                    SourceDesc = sourceDesc,
                    SourceRef = sourceRef,
                    SourceNotes = sourceNotes,
                    SourceFileCount = sourceFileCount.ToInt32(),
                    SourceId = sourceId.ToGuid() ,
                    Files = tp,
                    Parishs = parishs.ParseToGuidList(),
                    SourceTypes = sourceTypes.ParseToIntList()
                };

            var iModel = new SourceSearch(new Security(new WebUser()));

            try
            {
                iModel.Update(ssobj, new SourceValidator(ssobj));

            }

            catch (Exception ex1)
            {
                retVal = ex1.Message;
            }

            return WebHelper.MakeReturn(ssobj.SourceId.ToString(), retVal);
        }
        public static string SourceDto(this CSVField self, SourceDto sourceDto)
        {
            switch (self)
            {
                case CSVField.SourceDate:
                    return sourceDto.SourceDateStr;
                case CSVField.SourceDateTo:
                    return sourceDto.SourceDateStrTo;
                case CSVField.SourceRef:
                    return sourceDto.SourceRef;
                case CSVField.SourceParish:
                    return sourceDto.Parishs.ParseToCSV("|");
                case CSVField.SourceType:
                    return sourceDto.SourceTypes.ParseToCSV("|");
                case CSVField.SourceDesc:
                    return sourceDto.SourceDesc;
                case CSVField.SourceOrigLocat:
                    return sourceDto.OriginalLocation;
                case CSVField.IsCopyHeld:
                    return sourceDto.IsCopyHeld.ToString();
                case CSVField.IsViewed:
                    return sourceDto.IsViewed.ToString();
                case CSVField.IsThackrayFound:
                    return sourceDto.IsThackrayFound.ToString();
                case CSVField.Notes:
                    return sourceDto.SourceNotes;
                case CSVField.SourceId:
                    return sourceDto.SourceId.ToString();
                case CSVField.VirtualLocation:
                    return sourceDto.VirtualLocation;

            }

            return "";
        }
        public IHttpActionResult GetSource(string sourceId)
        {
            var ssobj = new SourceDto();

            var sourceSearch = new SourceSearch(new Security(new WebUser()));

            string retVal = "";

            try
            {
                ssobj = sourceSearch.Get(new SourceDto() { SourceId = sourceId.ToGuid() });

            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }

            if (retVal != "")
            {
                return Content(HttpStatusCode.BadRequest, retVal);
            }

            return Ok(ssobj.ToSourceAjaxDto());
        }
        public SourceAjaxDto GetSource(string sourceId)
        {
            var ssobj = new SourceDto();

            var iModel = new SourceSearch(new Security(new WebUser()));

            string retVal = "";

            try
            {
               ssobj = iModel.Get(new SourceDto(){SourceId = sourceId.ToGuid()});

            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }
            finally
            {
                if (retVal != "") retVal += Environment.NewLine;
                ssobj.ErrorStatus += retVal;

            }

            return ssobj.ToSourceAjaxDto();
        }
        public SourceDto Get(SourceDto sourceDto)
        {
            if (sourceDto == null)
                sourceDto = new SourceDto();

            if (!_security.IsvalidSelect()) throw new SecurityException("Missing select permission");

            sourceDto = _sourceDal.GetSource(sourceDto.SourceId);

            sourceDto.Files = _filesDal.GetFilesByParent(sourceDto.SourceId);

            sourceDto.SourceTypes = _sourceTypesDal.GetSourceTypeIds(sourceDto.SourceId);

            sourceDto.Parishs = _sourceMappingParishsDal.GetParishIds(sourceDto.SourceId);

            return sourceDto;
        }
        public IHttpActionResult AddSource(ServiceSourceAdd serviceSourceAdd)
        {
            string retVal = "";

            var jss = new JavaScriptSerializer();

            var obj = jss.Deserialize<dynamic>(serviceSourceAdd.FileIds?? "");

            var tp = new List<ServiceFile>();

            if (obj != null)
                foreach (dynamic item in obj)
                    tp.Add(new ServiceFile(item["url"], item["desc"], item["id"]));

            var ssobj = new SourceDto()
            {
                IsCopyHeld = serviceSourceAdd.IsCopyHeld.ToBool(),
                IsThackrayFound = serviceSourceAdd.IsThackrayFound.ToBool(),
                IsViewed = serviceSourceAdd.IsViewed.ToBool(),
                OriginalLocation = serviceSourceAdd.OriginalLocation,
                SourceDateStr = serviceSourceAdd.SourceDateStr,
                SourceDateStrTo = serviceSourceAdd.SourceDateStrTo,
                SourceDesc = serviceSourceAdd.SourceDesc,
                SourceRef = serviceSourceAdd.SourceRef,
                SourceNotes = serviceSourceAdd.SourceNotes,
                SourceFileCount = serviceSourceAdd.SourceFileCount.ToInt32(),
                SourceId = serviceSourceAdd.SourceId.ToGuid(),
                Files = tp,
                Parishs = serviceSourceAdd.Parishs.ParseToGuidList(),
                SourceTypes = serviceSourceAdd.SourceTypes.ParseToIntList()
            };

            var sourceSearch = new SourceSearch(new Security(new WebUser()));

            try
            {
                sourceSearch.Update(ssobj, new SourceValidator(ssobj));

            }

            catch (Exception ex1)
            {
                retVal = ex1.Message;
            }

            if (retVal != "")
            {
                return Content(HttpStatusCode.BadRequest, retVal);
            }

            return Ok(ssobj.SourceId.ToString());
        }
        public void DeleteRecords(SourceDto sourceDto)
        {
            if (!_security.IsValidDelete()) throw new SecurityException("Missing delete permission");

            _sourceDal.DeleteSource2(sourceDto.SourceId);
        }
        private void UpdateRelatedData(SourceDto sourceDto)
        {
            _smDal.WriteFilesToSource(sourceDto.SourceId, sourceDto.Files, sourceDto.UserId);

            _smDal.WriteSourceTypesToSource(sourceDto.SourceId, sourceDto.SourceTypes, sourceDto.UserId);

            _smDal.WriteParishsToSource(sourceDto.SourceId, sourceDto.Parishs, sourceDto.UserId);
        }
        private void Insert(SourceDto sourceDto)
        {
            if (!_security.IsValidInsert()) throw new SecurityException("Missing insert permission");

            _sourceDal.InsertSource(sourceDto);

            UpdateRelatedData(sourceDto);
        }
        public void Update(SourceDto sourceDto, IValidator validator = null)
        {
            if (validator == null)
                validator = new Validator();

            if (!validator.ValidEntry()) throw new InvalidDataException(validator.GetErrors());

            if (sourceDto.SourceId == Guid.Empty)
            {
                Insert(sourceDto);
            }
            else
            {
                Edit(sourceDto);
            }
        }
        public SourceValidator(SourceDto sourceAjaxDto)
        {
            _sourceAjaxDto = sourceAjaxDto;

            Validate();
        }