private InstitutionViewModel ParseToViewModel(Institution institution)
        {
            var retorno = new InstitutionViewModel();

            retorno.InstitutionId = institution.InstitutionId;
            retorno.CNPJ          = institution.CNPJ;
            retorno.FantasyName   = institution.FantasyName;
            retorno.Description   = institution.Description;
            retorno.PhotosModel   = ParseToPhotoModel(institution.Photos);
            retorno.Phones        = ParseToPhoneModel(institution.Phones);
            retorno.Adresses      = ParseToAddresModel(institution.Adresses);
            retorno.Email         = institution.User.Email;

            return(retorno);
        }
Example #2
0
        public ActionResult Search()
        {
            //string sqlExpression = "SELECT COUNT(InstitutionID) FROM Institution;";

            //InfoFromDB<int> cntInst = new InfoFromDB<int>();

            //cntInst.Request(sqlExpression);

            //ViewBag.InstitutionCount = "Количество образовательных организаций: " + cntInst.Result[0];

            ViewBag.InstitutionInfo = new List <InstitutionFullInfo <DateTime> >();
            InstitutionViewModel vmm = new InstitutionViewModel();

            return(View(vmm));
        }
Example #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            InstitutionViewModel obj = new InstitutionViewModel();
            string id   = txtIdNumber.Text;
            var    user = obj.getRegisteredUser(id);

            if (user == null)
            {
                messageBox("Enter the correct ID Number");
            }
            else
            {
                this.Frame.Navigate(typeof(UpdatePage), obj.getRegisteredUser(id));
            }
        }
Example #4
0
        public ActionResult Crear([Bind(Include = "institution_id,name")] InstitutionViewModel pInstitutionViewModel)
        {
            // TODO: Add insert logic here

            if (pInstitutionViewModel == null)
            {
                return(HttpNotFound());
            }
            pInstitutionViewModel.institution_id  = 0;
            pInstitutionViewModel.user_id_created = AuthorizeUserAttribute.UsuarioLogeado().user_id;

            InstitutionBL oBL = new InstitutionBL();

            oBL.Agregar(pInstitutionViewModel);
            return(RedirectToAction("Index"));
        }
Example #5
0
        public ActionResult Edit(InstitutionViewModel institutionViewModel)
        {
            if (ModelState.IsValid)
            {
                Institution institution = db.Institutions.Find(institutionViewModel.InstitutionID);

                institution.InstitutionName  = institutionViewModel.InstitutionName;
                institution.CountryCountryID = institutionViewModel.CountryCountryID;
                institution.LastUpdatedBy    = (int)Membership.GetUser().ProviderUserKey;
                //institution.LastUpdatedOn = DateTimeOffset.Now;

                db.Entry(institution).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CountryList = new SelectList(db.Countries.Where(c => c.Status == "Current").OrderBy(c => c.CountryName).AsEnumerable(), "CountryID", "CountryName", institutionViewModel.CountryCountryID);
            return(View(institutionViewModel));
        }
Example #6
0
        public IActionResult DetailInstitution(int?id)
        {
            InstitutionViewModel institutionViewModel = new InstitutionViewModel()
            {
                Institution         = new Institution(),
                InstitutionTypeList = _unitWork.InstitutionType.GetAll().Select(it => new SelectListItem
                {
                    Text  = it.Name,
                    Value = it.Id.ToString()
                })
            };

            institutionViewModel.Institution = _unitWork.Institution.Get(id.GetValueOrDefault());
            if (institutionViewModel.Institution == null)
            {
                return(NotFound());
            }

            return(View(institutionViewModel));
        }
Example #7
0
        //
        // GET: /Institution/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Institution institution = db.Institutions.Find(id);

            if (institution == null)
            {
                return(HttpNotFound());
            }

            InstitutionViewModel institutionVM = new InstitutionViewModel()
            {
                InstitutionID    = institution.InstitutionID,
                InstitutionName  = institution.InstitutionName,
                CountryCountryID = institution.CountryCountryID
            };

            ViewBag.CountryList = new SelectList(db.Countries.Where(c => c.Status == "Current").OrderBy(c => c.CountryName).AsEnumerable(), "CountryID", "CountryName", institutionVM.CountryCountryID);

            return(View(institutionVM));
        }
Example #8
0
        public HttpResponseMessage SaveInstitution(HttpRequestMessage request, InstitutionViewModel institution)
        {
            var newInstitution = new Institution()
            {
                ID      = institution.ID,
                Name    = institution.Name,
                Type    = institution.Type,
                Website = institution.Website
            };

            _studentApi.SaveInstitution(newInstitution);

            var model = new InstitutionViewModel();

            var institutionVm = model.MapSingleInstitution(newInstitution);

            var response = request.CreateResponse(HttpStatusCode.Created, institutionVm);

            return(response);
        }
Example #9
0
        private void btnPassword_Click(object sender, RoutedEventArgs e)
        {
            string id = txtIDnumber.Text;
            string password, username;
            var    obj = new InstitutionViewModel();

            var user = obj.getUser(id);

            if (user != null)
            {
                username = user.email;
                password = user.password;

                messageBox("password is " + password + "username is " + username);
            }
            else
            {
                messageBox("The user does not exist please make sure you enter a valid ID");
            }
        }
        public ActionResult Edit(InstitutionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var institution = ParseCompleteToInstitution(model);

                institutionService.Edit(institution);

                return(View("MensagemSucessoAlteracaoCadastro"));
            }
            else
            {
                var model1 = institutionService.GetByUserEmail(model.Email);

                model.Categories  = GetCategories();
                model.PhotosModel = ParseToPhotoModel(model1.Photos);
                model.Adresses    = ParseToAddresModel(model1.Adresses);

                return(View("EditarCadastro", model));
            }
        }
        public ActionResult Edit(
            [Bind(Include = "InstitutionId,InstitutionEndpointAddress")] InstitutionViewModel institution)
        {
            if (ModelState.IsValid)
            {
                var repositoryInstitution =
                    _repository.Read(institution.InstitutionId);

                if (repositoryInstitution == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                repositoryInstitution.InstitutionName            = institution.InstitutionName;
                repositoryInstitution.InstitutionEndpointAddress = institution.InstitutionEndpointAddress;
                repositoryInstitution.Address = institution.Address;

                _repository.Update(repositoryInstitution);
                return(RedirectToAction("Index"));
            }
            return(View(institution));
        }
Example #12
0
 public InstitutionViewModel Post([FromBody] InstitutionViewModel institution)
 {
     institution = _institutionAppService.Add(institution);
     institution.AddRangeLink(_institutionEnricher.CreateLinks(Method.Post, institution));
     return(institution);
 }
        private Institution ParseCompleteToInstitution(InstitutionViewModel institution)
        {
            var retorno = new Institution();

            retorno.InstitutionId    = institution.InstitutionId;
            retorno.CNPJ             = institution.CNPJ;
            retorno.FantasyName      = institution.FantasyName;
            retorno.SocialName       = institution.SocialName;
            retorno.AcceptedTermsUse = institution.AcceptedTermsUse;
            retorno.Description      = institution.Description;

            retorno.User = new User {
                Email = institution.Email, Password = institution.Password
            };

            retorno.Phones = new List <Phone>();
            foreach (var fone in institution.Phones)
            {
                retorno.Phones.Add(
                    new Phone
                {
                    InstitutionId = retorno.InstitutionId,
                    AreaCode      = fone.AreaCode,
                    Number        = fone.Number
                });
            }

            retorno.Adresses = new List <Address>();
            foreach (var address in institution.Adresses)
            {
                retorno.Adresses.Add(new Address
                {
                    InstitutionId = retorno.InstitutionId,
                    City          = address.City,
                    Number        = address.Number,
                    PostalCode    = address.PostalCode,
                    State         = address.State,
                    Street        = address.Street
                });
            }

            retorno.Categories = new List <Category>();

            foreach (var item in institution.SelectedCategories)
            {
                retorno.Categories.Add(new Category {
                    Description = item.ToString()
                });
            }

            retorno.Photos = new List <Photo>();

            var listImgs = new List <string>();

            if (institution.NewPhotos != null && institution.NewPhotos.Count > 0)
            {
                institution.Photos = institution.NewPhotos;
            }

            foreach (var item in institution.Photos)
            {
                if (item != null)
                {
                    Stream stream = item.InputStream;
                    using (var memoryStream = new MemoryStream())
                    {
                        stream.CopyTo(memoryStream);
                        retorno.Photos.Add(new Photo {
                            Binary = memoryStream.ToArray()
                        });
                    }
                }
            }

            return(retorno);
        }
Example #14
0
 public ActionResult Post([FromBody] InstitutionViewModel vm)
 {
     ViewModelService.Save(vm);
     return(Ok());
 }
        public IActionResult Institution(InstitutionViewModel model, string submit)
        {
            lock (lockObject)
            {
                logger.LogInformation($"Usao u post institution thread {Thread.CurrentThread.ManagedThreadId}");
                try
                {
                    Institution institution = null;
                    switch (submit)
                    {
                    case "Save":
                        institution = repository.GetInstitutionById(model.Id);
                        if (institution != null)     // institucija vec postoji
                        {
                            ViewBag.UserMessage = $"Trazena institucija sa imenom: {institution.Id} vec postoji u bazi!";
                        }
                        else
                        {
                            institution = new Institution()
                            {
                                Id = model.Id,
                                InstitutionAddress = model.InstitutionAddress,
                                InstitutionHolder  = model.InstitutionHolder,
                                TimeStamp          = DateTime.UtcNow.Ticks
                            };
                            model.SearchName = "";
                            repository.SaveInstitution(institution);
                            bool result = repository.SaveAll();
                            if (result)
                            {
                                ViewBag.UserMessage = $"Institucija {institution.Id} uspesno dodata u bazu.";
                                model = new InstitutionViewModel();
                            }
                            else
                            {
                                ViewBag.UserMessage = $"Institucija {institution.Id} nije uspesno dodata u bazu.";
                            }
                        }
                        break;

                    case "Update":     // Prvo moramo proveriti da li je ono sto je inicijalno ucitano preko serch-a
                        institution = repository.GetInstitutionById(model.Id);
                        if (institution != null && institution.TimeStamp == model.TimeStamp)
                        {
                            if (institution.Id != model.Id)
                            {
                                ViewBag.UserMessage = $"Ne moze se promeniti ime {institution.Id}, posto se pokusava promenit ime na {model.Id} ";
                                break;
                            }
                            institution.InstitutionAddress = model.InstitutionAddress;
                            institution.InstitutionHolder  = model.InstitutionHolder;
                            institution.TimeStamp          = DateTime.UtcNow.Ticks;
                            repository.UpdateInstitution(institution);
                            bool result = repository.SaveAll();
                            if (result)
                            {
                                ViewBag.UserMessage = $"Institucija {institution.Id} uspesno izmenjena u bazi.";
                            }
                            else
                            {
                                ViewBag.UserMessage = $"Institucija {institution.Id} nije uspesno izmenjena u bazi.";
                            }
                        }
                        else
                        {
                            ViewBag.UserMessage = $"Institucija {model.Id} koja se zeli promeniti je u medjuvremeu promenjena ili obrisana od strane drugog korisnika. Molim vas ucitajte ponovo instituciju.";
                        }
                        break;

                    case "Delete":
                        institution = repository.GetInstitutionById(model.Id);
                        if (institution != null && institution.TimeStamp == model.TimeStamp)
                        {
                            if (institution.Id != model.Id)
                            {
                                ViewBag.UserMessage = $"Ne moze se promeniti ime {institution.Id}, posto se pokusava promenit ime na {model.Id} ";
                                break;
                            }
                            repository.DeleteInstitution(institution);
                            bool result = repository.SaveAll();
                            if (result)
                            {
                                ViewBag.UserMessage = $"Institucija {institution.Id} uspesno obrisana iz bazi.";
                                model = new InstitutionViewModel();
                            }
                            else
                            {
                                ViewBag.UserMessage = $"Institucija {institution.Id} nije uspesno obrisana iz bazi.";
                            }
                        }
                        else
                        {
                            ViewBag.UserMessage = $"Institucija {model.Id} je u medjuvremenu obrisana od strane drugog korisnika.";
                        }
                        break;

                    case "searchForm":
                        institution = repository.GetInstitutionById(model.SearchName);
                        if (institution != null)     // pronadjena
                        {
                            model.SearchName         = "";
                            model.Id                 = institution.Id;
                            model.InstitutionAddress = institution.InstitutionAddress;
                            model.InstitutionHolder  = institution.InstitutionHolder;
                            model.TimeStamp          = institution.TimeStamp;
                            ViewBag.Enable           = "Enabled"; // enabled samo ako je pronadjen iz baze
                        }
                        else
                        {
                            ViewBag.CantFind = "Trazena institucija ne postoji u bazi";
                        }

                        break;
                    }

                    ModelState.Clear(); // ljubim te u dupe!!! Potrebno da se trenutno onemoguci ugradjena validacija nad poljima koja ima bug
                }
                catch (Exception ex)
                {
                    ModelState.Clear();
                    //     ViewBag.CantFind(ex.Message); bude null
                }
                logger.LogInformation($"Zavrsava u post institution thread {Thread.CurrentThread.ManagedThreadId}");
                return(View(model));
            }
        }
Example #16
0
        public IActionResult InsertOrUpdateInstitution(InstitutionViewModel institutionViewModel)
        {
            if (ModelState.IsValid)
            {
                Action action = Action.None;
                if (institutionViewModel.Institution.Id == 0)
                {
                    action = Action.Create;
                    _unitWork.Institution.Add(institutionViewModel.Institution);
                }
                else
                {
                    action = Action.Update;
                    institutionViewModel.Institution.Email = institutionViewModel.Institution.Email.ToLower();
                    _unitWork.Institution.Update(institutionViewModel.Institution);
                }

                try
                {
                    _unitWork.Save();
                    if (action == Action.Create)
                    {
                        _notyfService.Success("Institución creada correctamente.");
                    }
                    if (action == Action.Update)
                    {
                        _notyfService.Success("Institución actualizada correctamente.");
                    }

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("IX_Institutions_Name"))
                    {
                        _notyfService.Error("Ya existe un Instución con el mismo nombre.");

                        institutionViewModel.InstitutionTypeList = _unitWork.InstitutionType.GetAll().Select(it => new SelectListItem
                        {
                            Text  = it.Name,
                            Value = it.Id.ToString()
                        });

                        return(View(institutionViewModel));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }
            else
            {
                institutionViewModel.InstitutionTypeList = _unitWork.InstitutionType.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                });

                if (institutionViewModel.Institution.Id != 0)
                {
                    institutionViewModel.Institution = _unitWork.Institution.Get(institutionViewModel.Institution.Id);
                }
            }
            return(View(institutionViewModel));
        }
Example #17
0
        public IEnumerable <Link> CreateLinks(Method method, InstitutionViewModel content = null)
        {
            var linkContainer = new LinkContainer();

            if (_urlHelper != null)
            {
                var getAll = new Link()
                {
                    Method = "GET", Rel = "get all institutions", Href = _urlHelper.Link("GetAllInstitutions", new { })
                };
                var insert = new Link()
                {
                    Method = "POST", Rel = "insert institution", Href = _urlHelper.Link("InsertInstitution", new { })
                };

                var getById = new Link();
                var update  = new Link();
                var delete  = new Link();

                if (content != null)
                {
                    getById = new Link()
                    {
                        Method = "GET", Rel = "get institution by id", Href = _urlHelper.Link("GetInstitutionById", new { id = content.Id })
                    };
                    update = new Link()
                    {
                        Method = "PUT", Rel = "update institution", Href = _urlHelper.Link("UpdateInstitution", new { id = content.Id })
                    };
                    delete = new Link()
                    {
                        Method = "DELETE", Rel = "delete institution", Href = _urlHelper.Link("DeleteInstitution", new { id = content.Id })
                    };
                }

                switch (method)
                {
                case Method.GetAll:
                    linkContainer.AddLink(getAll);
                    linkContainer.AddLink(insert);
                    break;

                case Method.Get:
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Post:
                    linkContainer.AddLink(insert);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(delete);
                    break;

                case Method.Put:
                    linkContainer.AddLink(update);
                    linkContainer.AddLink(getById);
                    linkContainer.AddLink(delete);
                    break;
                }
                linkContainer.Links[0].Rel = "self";
            }
            return(linkContainer.Links);
        }
 public void Update(InstitutionViewModel institution)
 {
     //throw new NotImplementedException();
 }
 public void Add(InstitutionViewModel institution)
 {
     _bus.SendCommand(new AddInstitutionCommand(institution.Name, institution.Email, institution.Phone, institution.AddressId));
 }