Пример #1
0
        public AdministrationServiceResult CreateOrUpdate(DoctorsOfficeInputModel inputModel, bool setAsActivePage = false)
        {
            AdministrationServiceResult result;

            var referencePage = this.getPage(inputModel.page.Id);

            if (referencePage != null)
            {
                result = CreatePageFromReference(inputModel, referencePage);
                if (result.IsValid == true)
                {
                    DoctorsOfficePage page = result.ResultObject as DoctorsOfficePage;
                    page.Active = false;
                    context.DoctorsOfficePages.Add(page);
                    context.SaveChanges();

                    if (setAsActivePage == true)
                    {
                        this.ActivatePage(page, referencePage);
                    }
                }
            }
            else
            {
                result = new AdministrationServiceResult();
                result.Errors.Add("Pagina no válida");
            }
            return(result);
        }
Пример #2
0
        private AdministrationServiceResult CreatePageFromReference(DoctorsOfficeInputModel inputModel, DoctorsOfficePage referencePage)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();
            var specification = new DoctorsOfficeValidInputModelSpecification(referencePage);
            var brokenRules   = specification.brokenRules(inputModel);

            result.Errors.AddRange(brokenRules);

            if (result.IsValid)
            {
                var page = inputModel.page;
                if (page.Equals(referencePage) == false)
                {
                    var fileService    = new FileService();
                    var processedFIles = fileService.processFiles(inputModel.uploadedFiles, "~/UploadedFiles");
                    fileService.mapFilesToSectionForCreateOrUpdate(page.HeadImages, referencePage.HeadImages, processedFIles);
                    fileService.mapFilesToSectionForCreateOrUpdate(page.ServicesSection, referencePage.ServicesSection, processedFIles);
                    page.CreationDate   = DateTime.Now;
                    result.ResultObject = page;
                }
                else
                {
                    result.Errors.Add("Esta página ya se encuentra en el catálogo");
                }
            }
            return(result);
        }
Пример #3
0
        private AdministrationServiceResult CreatePageFromReference(WhoWeAreInputModel inputModel, WhoWeArePage referencePage)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();
            var specification = new WhoWeAreValidInputModelWIthReferencePageSpecification(referencePage);
            var brokenRules   = specification.brokenRules(inputModel);

            result.Errors.AddRange(brokenRules);

            if (result.IsValid)
            {
                var page = inputModel.page;
                if (page.Equals(referencePage) == false)
                {
                    var fileService    = new FileService();
                    var processedFIles = fileService.processFiles(inputModel.uploadedFiles, "~/UploadedFiles");
                    fileService.mapFilesToSectionForCreateOrUpdate(page.HeadImages, referencePage.HeadImages, processedFIles);
                    fileService.mapFilesToSectionForCreateOrUpdate(page.ValuesSection, referencePage.ValuesSection, processedFIles);
                    fileService.mapFilesToSectionForCreateOrUpdate(page.HistoryImages, referencePage.HistoryImages, processedFIles);
                    var adFileName = page.AdSection.ImageFileName;
                    page.AdSection.ImageFileName = (String.IsNullOrEmpty(adFileName) == false && processedFIles.ContainsKey(adFileName)) ? processedFIles[adFileName] : referencePage.AdSection.ImageFileName;
                    page.CreationDate            = DateTime.Now;
                    result.ResultObject          = page;
                }
                else
                {
                    result.Errors.Add("Esta página ya se encuentra en el catálogo");
                }
            }

            return(result);
        }
        public async Task <AdministrationServiceResult> create(BranchInputModel inputData)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();

            var state = context.Estados.Where(st => st.Id == inputData.State).FirstOrDefault();

            if (state != null)
            {
                var city = context.Municipios.Where(c => c.Id == inputData.City).FirstOrDefault();
                if (city != null)
                {
                    if (inputData.BranchName.Trim().Length != 0)
                    {
                        if (inputData.BranchAddress.Trim().Length != 0)
                        {
                            Branch branch = getTargetBranch(inputData);

                            if (branch != null)
                            {
                                branch.State = state;
                                branch.City  = city;
                                if (inputData.BranchId == 0)
                                {
                                    context.Branchs.Add(branch);
                                }
                                else
                                {
                                    context.Entry(branch).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                            else
                            {
                                result.Errors.Add("Sucursal no válida");
                            }
                            await context.SaveChangesAsync();
                        }
                        else
                        {
                            result.Errors.Add("Dirección de sucursal no válida");
                        }
                    }
                    else
                    {
                        result.Errors.Add("Nombre de sucursal no válido");
                    }
                }
                else
                {
                    result.Errors.Add("Ciudad no válida");
                }
            }
            else
            {
                result.Errors.Add("Estado no válido");
            }

            return(result);
        }
Пример #5
0
        private AdministrationServiceResult createLaboratory(LaboratoryInputModel inputData, Municipios city, Estados state)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();
            Laboratory laboratory = new Laboratory
            {
                Name   = inputData.Name,
                Active = inputData.Active,
                City   = city,
                State  = state
            };

            context.Laboratories.Add(laboratory);
            return(result);
        }
Пример #6
0
        private AdministrationServiceResult ActivatePage(DoctorsOfficePage targetPage, DoctorsOfficePage activePage)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();

            if (activePage != null && targetPage != null)
            {
                activePage.Active = false;
                targetPage.Active = true;
                context.SaveChanges();
            }
            else
            {
                result.Errors.Add("Parámetros no válidos");
            }

            return(result);
        }
Пример #7
0
        public AdministrationServiceResult DeletePage(int?id)
        {
            var result = new AdministrationServiceResult();

            var page = this.getPage(id);

            if (page == null)
            {
                result.Errors.Add("Página no encontrada");
            }
            else
            {
                this.context.DoctorsOfficePages.Remove(page);
                this.context.SaveChanges();
            }

            return(result);
        }
Пример #8
0
        public AdministrationServiceResult GetPreviewPage()
        {
            var result  = new AdministrationServiceResult();
            var preview = context.PagePreviews.Find("DoctorsOffice");

            if (preview == null)
            {
                result.Errors.Add("Página no válida");
            }
            else
            {
                var str             = new MemoryStream(preview.PageValue);
                var binaryFormatter = new BinaryFormatter();
                var previewPage     = binaryFormatter.Deserialize(str) as DoctorsOfficePage;
                result.ResultObject = previewPage;
            }

            return(result);
        }
Пример #9
0
        private AdministrationServiceResult updateLaboratory(LaboratoryInputModel inputData, Municipios city, Estados state)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();
            var laboratory = context.Laboratories.Where(l => l.ID == inputData.Id).FirstOrDefault();

            if (laboratory != null)
            {
                laboratory.Name   = inputData.Name;
                laboratory.Active = inputData.Active;
                laboratory.City   = city;
                laboratory.State  = state;
                context.Entry(laboratory).State = EntityState.Modified;
            }
            else
            {
                result.Errors.Add("Laboratorio no válido");
            }
            return(result);
        }
Пример #10
0
        public AdministrationServiceResult addOrUpdateLaboratory(LaboratoryInputModel inputData)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();

            if (inputData != null)
            {
                var city = context.Municipios.Where(c => c.Id == inputData.CityId).FirstOrDefault();
                if (city == null)
                {
                    result.Errors.Add("Municipio no válido");
                }

                var state = context.Estados.Where(st => st.Id == inputData.StateId).FirstOrDefault();
                if (state == null)
                {
                    result.Errors.Add("Estado no válido");
                }

                if (result.IsValid)
                {
                    AdministrationServiceResult operationResult = null;
                    if (inputData.Id > 0)
                    {
                        operationResult = this.updateLaboratory(inputData, city, state);
                    }
                    else
                    {
                        operationResult = this.createLaboratory(inputData, city, state);
                    }
                    context.SaveChanges();
                    result.Errors.AddRange(operationResult.Errors);
                }
            }
            else
            {
                result.Errors.Add("Datos de entrada no válidos");
            }

            return(result);
        }
Пример #11
0
        public async Task <AdministrationServiceResult> create(PillarInputModel inputData)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();

            if (inputData.PillarName.Trim().Length != 0)
            {
                if (inputData.PillarDescription.Trim().Length != 0)
                {
                    Pillar pillar = getTargetPillar(inputData);

                    if (pillar != null)
                    {
                        if (inputData.PillarId == 0)
                        {
                            context.Pillars.Add(pillar);
                        }
                        else
                        {
                            context.Entry(pillar).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    else
                    {
                        result.Errors.Add("Pilar no válido");
                    }
                    await context.SaveChangesAsync();
                }
                else
                {
                    result.Errors.Add("Descripción de pilar no válida");
                }
            }
            else
            {
                result.Errors.Add("Nombre de pilar no válido");
            }

            return(result);
        }
Пример #12
0
        public AdministrationServiceResult PreviewPage(DoctorsOfficeInputModel inputModel)
        {
            AdministrationServiceResult result;

            var referencePage = this.getPage(inputModel.page.Id);

            if (referencePage != null)
            {
                result = CreatePageFromReference(inputModel, referencePage);
                if (result.IsValid == true)
                {
                    WhoWeArePage page = result.ResultObject as WhoWeArePage;
                    result.ResultObject = page;

                    IFormatter   formatter = new BinaryFormatter();
                    MemoryStream stream    = new MemoryStream();
                    formatter.Serialize(stream, page);
                    stream.Close();

                    var storedPagePreview = context.PagePreviews.Find("DoctorsOffice");
                    if (storedPagePreview != null)
                    {
                        context.PagePreviews.Remove(storedPagePreview);
                    }

                    context.PagePreviews.Add(new PagePreview {
                        PageName = "DoctorsOffice", PageValue = stream.GetBuffer()
                    });
                    context.SaveChanges();
                }
            }
            else
            {
                result = new AdministrationServiceResult();
                result.Errors.Add("Pagina no válida");
            }
            return(result);
        }
Пример #13
0
        public AdministrationServiceResult remove(int?id)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();

            if (id != null)
            {
                var laboraotry = context.Laboratories.Where(l => l.ID == id.Value).FirstOrDefault();
                if (laboraotry != null)
                {
                    context.Laboratories.Remove(laboraotry);
                    context.SaveChanges();
                }
                else
                {
                    result.Errors.Add("Laboratorio no válido");
                }
            }
            else
            {
                result.Errors.Add("Datos de entrada no válidos");
            }

            return(result);
        }