Exemplo n.º 1
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(DelegateManViewModel model)
        {
            var entity = model.ToEntity();

            this._DelegateMansRepository.Delete(entity);

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

            var entity = model.ToEntity();

            entity = this._DelegateMansRepository.Update(entity);

            ConditionFilter <DelegateMan, long> conditionFilter = new ConditionFilter <DelegateMan, long>()
            {
                Query = (x =>
                         x.ParentKeyDelegateManId == entity.Id)
            };
            var childs = this._DelegateMansRepository.Get(conditionFilter);

            if (childs.Count() > 0)
            {
                var ar = childs.FirstOrDefault(x => x.Language == Language.Arabic);
                ar.Name        = model.NameAr;
                ar.Description = model.DescriptionAr;
                this._DelegateMansRepository.Update(ar);

                var en = childs.FirstOrDefault(x => x.Language == Language.English);
                en.Name        = model.NameEn;
                en.Description = model.DescriptionEn;
                this._DelegateMansRepository.Update(en);
            }

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

            address.Description = model.Address;
            this._AddresssRepository.Update(address);

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

            mobile.Number = model.Phone;

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

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

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

            model = entity.ToModel();
            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DelegateManViewModel Add(DelegateManViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._DelegateMansRepository.Add(entity);

            var entityAr = new DelegateMan
            {
                Id          = entity.Id,
                Description = model.DescriptionAr,
                Name        = model.NameAr,
                Language    = Language.Arabic
            };

            entity.ChildTranslatedDelegateMans.Add(entityAr);
            this._DelegateMansRepository.Add(entityAr);

            var entityEn = new DelegateMan
            {
                Id          = entity.Id,
                Description = model.DescriptionEn,
                Name        = model.NameEn,
                Language    = Language.English
            };

            entity.ChildTranslatedDelegateMans.Add(entityEn);
            this._DelegateMansRepository.Add(entityEn);

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

            if (string.IsNullOrEmpty(model.Email) == false)
            {
                Mail mail = new Mail
                {
                    ObjectId   = entity.Id,
                    ObjectType = ObjectType.Delegate,
                    Email      = model.Email,
                    IsMain     = true,
                    IsVerified = true,
                    IsActive   = true
                };
                ThrowExceptionIfExist(mail);
                this._MailsRepository.Add(mail);
            }

            if (string.IsNullOrEmpty(model.Address) == false)
            {
                Address address = new Address
                {
                    ObjectId    = entity.Id,
                    ObjectType  = ObjectType.Delegate,
                    Description = model.Address,
                    IsMain      = true,
                    IsActive    = true
                };
                this._AddresssRepository.Add(address);
            }

            if (string.IsNullOrEmpty(model.Phone) == false)
            {
                Mobile mobile = new Mobile
                {
                    ObjectId   = entity.Id,
                    ObjectType = ObjectType.Delegate,
                    Number     = model.Phone,
                    IsActive   = true,
                    IsMain     = true
                };
                ThrowExceptionIfExist(mobile);
                this._MobilesRepository.Add(mobile);
            }

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

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