/// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(VendorViewModel model)
        {
            var entity = model.ToEntity();

            this._VendorsRepository.Delete(entity);

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

            var entity = model.ToEntity();

            entity = this._VendorsRepository.Update(entity);

            ConditionFilter <Vendor, long> conditionFilter = new ConditionFilter <Vendor, long>()
            {
                Query = (x =>
                         x.ParentKeyVendorId == entity.Id)
            };
            var childs = this._VendorsRepository.Get(conditionFilter);

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

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

            if (string.IsNullOrEmpty(model.Address) == false)
            {
                var address = this._AddresssRepository.Get().FirstOrDefault(x => x.IsActive == true && x.IsMain == true && x.ObjectType == ObjectType.Vendor && x.ObjectId == model.Id);

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

            if (string.IsNullOrEmpty(model.Phone) == false)
            {
                Mobile mobile = this._MobilesRepository.Get().FirstOrDefault(x => x.IsActive == true && x.IsMain == true && x.ObjectType == ObjectType.Vendor && x.ObjectId == entity.Id);
                if (mobile != null)
                {
                    mobile.Number = model.Phone;
                    this._MobilesRepository.Update(mobile);
                }
                else
                {
                    Mobile newMobile = new Mobile
                    {
                        IsActive   = true,
                        IsMain     = true,
                        ObjectType = ObjectType.Vendor,
                        ObjectId   = entity.Id,
                        Number     = model.Phone
                    };
                    this._MobilesRepository.Add(newMobile);
                }
            }

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

            model = entity.ToModel();
            return(model);
        }
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public VendorViewModel Add(VendorViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._VendorsRepository.Add(entity);

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

            entity.ChildTranslatedVendors.Add(entityAr);
            this._VendorsRepository.Add(entityAr);

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

            entity.ChildTranslatedVendors.Add(entityEn);
            this._VendorsRepository.Add(entityEn);


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

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

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

            this._unitOfWork.Commit();

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