Ejemplo n.º 1
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DonatorViewModel Add(DonatorViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._DonatorsRepository.Add(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            this._AddresssRepository.Add(new Address {
                ObjectId = entity.Id, ObjectType = ObjectType.Donator, IsActive = true, IsMain = true, Description = model.Address
            });

            this._MailsRepository.Add(new Mail {
                ObjectId = entity.Id, ObjectType = ObjectType.Donator, IsActive = true, IsMain = true, Email = model.Email
            });

            this._MobilesRepository.Add(new Mobile {
                ObjectId = entity.Id, ObjectType = ObjectType.Donator, IsActive = true, IsMain = true, Number = model.Phone
            });

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(DonatorViewModel model)
        {
            var entity = model.ToEntity();

            this._DonatorsRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DonatorViewModel Update(DonatorViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._DonatorsRepository.Update(entity);

            Mobile mobile = this._MobilesRepository.Get().FirstOrDefault(x => x.ObjectId == entity.Id && x.ObjectType == ObjectType.Donator);

            mobile.Number = model.Phone;
            this._MobilesRepository.Update(mobile);

            Mail mail = this._MailsRepository.Get().FirstOrDefault(x => x.ObjectId == entity.Id && x.ObjectType == ObjectType.Donator);

            mail.Email = model.Email;
            this._MailsRepository.Update(mail);

            Address address = this._AddresssRepository.Get().FirstOrDefault(x => x.ObjectId == entity.Id && x.ObjectType == ObjectType.Donator);

            if (address == null)
            {
                address = new Address
                {
                    ObjectId    = entity.Id,
                    ObjectType  = ObjectType.Donator,
                    Description = model.Address,
                    IsActive    = true,
                    IsMain      = true
                };
                this._AddresssRepository.Add(address);
            }
            else
            {
                address.Description = model.Address;
                this._AddresssRepository.Update(address);
            }

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }