Ejemplo n.º 1
0
 public static void FillDto(Models.ViewLocation entity, ViewModels.Location viewlocation)
 {
     viewlocation.Parent        = entity.Parent;
     viewlocation.ParentCode    = entity.ParentCode;
     viewlocation.Root          = entity.Root;
     viewlocation.RootCode      = entity.RootCode;
     viewlocation.Id            = entity.Id;
     viewlocation.Title         = entity.Title;
     viewlocation.TitleFormated = entity.TitleFormated;
     viewlocation.Code          = entity.Code;
     viewlocation.FullCode      = entity.FullCode;
     viewlocation.CustomerId    = entity.CustomerId;
     viewlocation.TypeId        = entity.TypeId;
     viewlocation.Remark        = entity.Remark;
     viewlocation.IsVirtual     = entity.IsVirtual;
     viewlocation.IsDeleted     = entity.IsDeleted;
     viewlocation.IsActive      = entity.IsActive;
     viewlocation.ParentId      = entity.ParentId;
     viewlocation.CityId        = entity.CityId;
     viewlocation.Address       = entity.Address;
     viewlocation.PostalCode    = entity.PostalCode;
     viewlocation.Website       = entity.Website;
     viewlocation.RootLocation  = entity.RootLocation;
     viewlocation.City          = entity.City;
     viewlocation.State         = entity.State;
     viewlocation.Country       = entity.Country;
     viewlocation.CountryId     = entity.CountryId;
     viewlocation.StateId       = entity.StateId;
     viewlocation.SortName      = entity.SortName;
     viewlocation.Type          = entity.Type;
     viewlocation.Items         = entity.Items;
     viewlocation.HasItems      = entity.HasItems;
 }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> DeleteLocation(ViewModels.Location dto)
        {
            var entity = await unitOfWork.LocationRepository.GetByID(dto.Id);

            if (entity == null)
            {
                return(NotFound());
            }



            var canDelete = unitOfWork.LocationRepository.CanDelete(entity);

            if (canDelete.Code != HttpStatusCode.OK)
            {
                return(canDelete);
            }

            unitOfWork.LocationRepository.Delete(entity);

            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            return(Ok(dto));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostLocation(ViewModels.Location dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            var validate = unitOfWork.LocationRepository.Validate(dto);

            if (validate.Code != HttpStatusCode.OK)
            {
                return(validate);
            }

            Location entity      = null;
            var      oldFullCode = string.Empty;

            if (dto.Id == -1)
            {
                entity = new Location();
                unitOfWork.LocationRepository.Insert(entity);
            }

            else
            {
                entity = await unitOfWork.LocationRepository.GetByID(dto.Id);

                oldFullCode = entity.FullCode;
            }

            if (entity == null)
            {
                return(Exceptions.getNotFoundException());
            }

            ViewModels.Location.Fill(entity, dto);


            if (dto.Id != -1 && entity.FullCode != oldFullCode)
            {
                unitOfWork.LocationRepository.UpdateChildren(entity, entity.FullCode);
            }
            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            dto.Id = entity.Id;
            return(Ok(dto));
        }
Ejemplo n.º 4
0
        public static MicrosoftDynamicsCRMbcgovLocation ToModel(this ViewModels.Location location)
        {
            MicrosoftDynamicsCRMbcgovLocation result = null;

            if (location != null)
            {
                result = new MicrosoftDynamicsCRMbcgovLocation()
                {
                    BcgovLocationid         = location.Id,
                    BcgovPrivatedwelling    = location.PrivateDwelling,
                    BcgovSettingdescription = location.SettingDescription,
                };
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert a view model location to a model location
        /// </summary>
        /// <param name="locationVM"></param>
        /// <returns></returns>
        public static MicrosoftDynamicsCRMbcgovLocation ToModel(this ViewModels.Location locationVM)
        {
            MicrosoftDynamicsCRMbcgovLocation result = null;

            if (locationVM != null)
            {
                result = new MicrosoftDynamicsCRMbcgovLocation()
                {
                    BcgovLocationid   = locationVM.Id,
                    BcgovPrvtdwelling = (int?)locationVM.PrivateDwelling
                                        //BcgovSettingdescription = location.SettingDescription,
                };

                result.BcgovPrvtdwelling = (int?)locationVM.PrivateDwelling;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public virtual CustomActionResult Validate(ViewModels.Location dto)
        {
            var checkByTitle = GetByTitleInParent(dto.Id, dto.ParentId, dto.Title);

            if (checkByTitle != null)
            {
                return(Exceptions.getDuplicateException("Location-01", "Title"));
            }
            var checkByCode = GetByFullCode(dto.Id, dto.CustomerId, dto.FullCode);

            if (checkByCode != null)
            {
                return(Exceptions.getDuplicateException("Location-02", "FullCode"));
            }

            return(new CustomActionResult(HttpStatusCode.OK, ""));
        }
Ejemplo n.º 7
0
        public static void Fill(Models.Location entity, ViewModels.Location viewlocation)
        {
            entity.Id    = viewlocation.Id;
            entity.Title = viewlocation.Title;

            entity.Code         = viewlocation.Code;
            entity.FullCode     = viewlocation.FullCode;
            entity.CustomerId   = viewlocation.CustomerId;
            entity.TypeId       = viewlocation.TypeId;
            entity.Remark       = viewlocation.Remark;
            entity.IsVirtual    = viewlocation.IsVirtual;
            entity.IsDeleted    = viewlocation.IsDeleted;
            entity.IsActive     = viewlocation.IsActive;
            entity.ParentId     = viewlocation.ParentId;
            entity.CityId       = viewlocation.CityId;
            entity.Address      = viewlocation.Address;
            entity.PostalCode   = viewlocation.PostalCode;
            entity.Website      = viewlocation.Website;
            entity.RootLocation = viewlocation.RootLocation;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Convert a Location to a ViewModel
        /// </summary>
        public static ViewModels.Location ToViewModel(this MicrosoftDynamicsCRMbcgovLocation location)
        {
            ViewModels.Location result = null;
            if (location != null)
            {
                result = new ViewModels.Location()
                {
                    Id              = location.BcgovLocationid,
                    Name            = location.BcgovName,
                    PrivateDwelling = (PrivateDwellingOptions?)location.BcgovPrvtdwelling,
                    //SettingDescription = location.BcgovSettingdescription //moved to EquipmentLocation
                };

                if (location.BcgovLocationAddress != null)
                {
                    result.Address = location.BcgovLocationAddress.ToViewModel();
                }
            }
            return(result);
        }
Ejemplo n.º 9
0
 public static void CopyValues(this MicrosoftDynamicsCRMbcgovEquipmentlocation to, ViewModels.Location from)
 {
     to.BcgovName = from.Name;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// copy values from a view model location to a model location
 /// </summary>
 /// <param name="to"></param>
 /// <param name="from"></param>
 public static void CopyValues(this MicrosoftDynamicsCRMbcgovLocation to, ViewModels.Location from)
 {
     to.BcgovName         = from.Name;
     to.BcgovPrvtdwelling = (int?)from.PrivateDwelling;
     //to.BcgovSettingdescription = from.SettingDescription;
 }