Exemplo n.º 1
0
        public Institution Create(Institution institution)
        {
            if (institution == null) return null;

            using (var db = new DozpContext())
            {
                db.Entry(institution).State = EntityState.Added;
                db.SaveChanges();
            }

            return institution;
        }
Exemplo n.º 2
0
        public bool Delete(Institution institution)
        {
            if (institution == null) return false;

            using (var db = new DozpContext())
            {
                db.Entry(institution).State = EntityState.Deleted;
                db.SaveChanges();
            }

            return true;
        }
Exemplo n.º 3
0
        public Institution Save(Institution institution)
        {
            if (institution == null) throw new ArgumentNullException("institution");

            if (String.IsNullOrEmpty(institution.Sigla))
                throw new ArgumentNullException("Neplatný parametr Sigla");

            if (String.IsNullOrEmpty(institution.Name))
                throw new ArgumentNullException("Neplatný parametr Name");

            InstitutionRepository repository = new InstitutionRepository();

            if (institution.InstitutionID == 0)
            {
                institution = repository.Create(institution);
            }
            else
            {
                institution = repository.Update(institution);
            }

            //return repository.Select(institution.institutionID);
            return institution;
        }
Exemplo n.º 4
0
        public Institution Update(Institution institution)
        {
            if (institution == null) return null;

            //try
            //{
            using (var db = new DozpContext())
            {
                db.Entry(institution).State = EntityState.Modified;
                db.SaveChanges();
            }
            //}
            //catch (DbEntityValidationException ex)
            //{
            //    StringBuilder sb = new StringBuilder();
            //    foreach (var result in ex.EntityValidationErrors)
            //    {
            //        sb.AppendLine(string.Format(ErrorMessage.ENTITY_VALIDATION_ERROR, result.Entry.Entity.GetType().Name, result.Entry.State));
            //        foreach (var error in result.ValidationErrors)
            //        {
            //            sb.AppendLine(String.Format(ErrorMessage.PROPERTY_VALIDATION_ERROR, error.PropertyName, error.ErrorMessage));
            //        }
            //    }
            //    throw new DbEntityValidationException(sb.ToString(), ex);
            //}

            return institution;
        }
Exemplo n.º 5
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            ErrorLabel.Text = "";

            try
            {
                if (Page.IsValid)
                {
                    int institutionID = Convert.ToInt32(Request.QueryString["id"]);
                    Comdat.DOZP.Core.Institution institution = null;

                    if (institutionID == 0)
                        institution = new Comdat.DOZP.Core.Institution();
                    else
                        institution = InstitutionComponent.Instance.GetByID(institutionID);

                    institution.Sigla = this.SiglaTextBox.Text.ToUpper();
                    institution.Name = this.NameTextBox.Text.Trim();
                    institution.Description = this.DescriptionTextBox.Text.Trim();
                    institution.Address = this.AddressTextBox.Text.Trim();
                    institution.Homepage = this.HomepageTextBox.Text.Trim();
                    institution.Email = this.EmailTextBox.Text.Trim();
                    institution.Telephone = this.TelephoneTextBox.Text.Trim();

                    InstitutionComponent.Instance.Save(institution);
                    Response.Redirect("Institutions.aspx", false);
                }
            }
            catch (Exception ex)
            {
                ErrorLabel.Text = String.Format("Chyba: {0}", ex.Message);
            }
        }