Esempio n. 1
0
        public bool EditPropertie(IPropertieDTO propertie)
        {
            bool result = false;

            using (RealPageDBContext context = new RealPageDBContext())
            {
                using (var transation = context.Database.BeginTransaction())
                {
                    try
                    {
                        Propertie editPropertie = context.Properties.Find(propertie.IdPropertie);
                        editPropertie = propertie.MapeadorPropertie <Propertie>(editPropertie);
                        context.Properties.Update(editPropertie);
                        context.SaveChanges();
                        transation.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        transation.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TR"></typeparam>
 /// <param name="origin"></param>
 /// <param name="destination"></param>
 /// <returns></returns>
 public static TR MapeadorPropertie <TR>(this IPropertieDTO origin, TR destination) where TR : IPropertieDTO, new()
 {
     if (destination == null)
     {
         destination = default(TR);
     }
     else
     {
         if (destination == null)
         {
             destination = new TR();
         }
         else
         {
             destination.Name     = origin.Name;
             destination.Location = origin.Location;
             destination.Price    = origin.Price;
             destination.IdUser   = origin.IdUser;
             if (origin.IdPropertie > 0)
             {
                 destination.Modified = DateTime.Now;
             }
             else
             {
                 destination.Created = DateTime.Now;
             }
         }
     }
     return(destination);
 }
Esempio n. 3
0
        private void PropertieValidateExist(IPropertieDTO propertie)
        {
            List <IPropertieQueryDTO> result = this._propertieDAL.Value.ListPropertie();

            if (result.Where(x => x.Name == propertie.Name).Any())
            {
                throw new Exception(string.Format(FieldsRequired.AlreadyExist, "Name"));
            }
        }
Esempio n. 4
0
        private void PropertieValidateFields(IPropertieDTO propertie, ActionOp action)
        {
            switch (action)
            {
            case ActionOp.Create:
                this.FieldsValidate(propertie);
                break;

            case ActionOp.Edit:
                if (propertie.IdPropertie == 0)
                {
                    throw new Exception(string.Format(FieldsRequired.FieldRe, "Id"));
                }
                this.FieldsValidate(propertie);
                break;
            }
        }
Esempio n. 5
0
        private void FieldsValidate(IPropertieDTO propertie)
        {
            if (propertie == null)
            {
                throw new Exception(string.Format(FieldsRequired.FieldsAreRequired));
            }
            if (string.IsNullOrEmpty(propertie.Name))
            {
                throw new Exception(string.Format(FieldsRequired.FieldRe, "Name"));
            }
            if (string.IsNullOrEmpty(propertie.Location))
            {
                throw new Exception(string.Format(FieldsRequired.FieldRe, "Location"));
            }

            if (propertie.IdUser == 0)
            {
                throw new Exception(string.Format(FieldsRequired.FieldRe, "owner"));
            }
        }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TR"></typeparam>
 /// <param name="origin"></param>
 /// <returns></returns>
 public static TR MapeadorPropertie <TR>(this IPropertieDTO origin) where TR : IPropertieDTO, new()
 {
     return(origin.MapeadorPropertie(new TR()));
 }
Esempio n. 7
0
 public bool EditPropertie(IPropertieDTO propertie)
 {
     this.PropertieValidateFields(propertie, ActionOp.Create);
     return(this._propertieDAL.Value.EditPropertie(propertie));
 }
Esempio n. 8
0
 public bool AddPropertie(IPropertieDTO propertie)
 {
     this.PropertieValidateExist(propertie);
     this.PropertieValidateFields(propertie, ActionOp.Create);
     return(this._propertieDAL.Value.AddPropertie(propertie));
 }