예제 #1
0
        public ActionResult Order(AddressBM address)
        {
            if (!ModelState.IsValid)
            {
                return(View(address));
            }

            string shippingAddress = "Address: " + address.ShippingAddress
                                     + Environment.NewLine + Environment.NewLine + "Town: " + address.Town
                                     + Environment.NewLine + Environment.NewLine
                                     + (string.IsNullOrEmpty(address.Description) ? ("Comments: " + address.Description) : "");

            Order currentOrder = new Order();

            currentOrder.Date            = DateTime.Now;
            currentOrder.Confirmed       = false;
            currentOrder.Buyer           = User.Identity.Name;
            currentOrder.ShippingAddress = shippingAddress;

            string       currentUsername = User.Identity.Name;
            ShoppingCart cart            = this._shoppingCartService.GetByUser(currentUsername);

            foreach (var item in cart.Items)
            {
                OrderProduct orderItem = AutoMapper.Mapper.Map <CartProduct, OrderProduct>(item);
                currentOrder.OrderedProducts.Add(orderItem);
            }

            this._orderService.AddOrUpdate(currentOrder);
            this._shoppingCartService.Clear(cart);

            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
        public void CreateAddressFailsCountry()
        {
            //Prueba la validación del país
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", null);

            ResultBM addressResult = addressBll.SaveAddress(addressBm);

            Assert.IsTrue(addressResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "No debería haber sido válido.");
            Assert.IsTrue(addressResult.description.Contains("país"), "No debería haber sido válido.");
        }
예제 #3
0
        private ResultBM create_invalid_person(PersonBM personBm)
        {
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  countryBm  = result.GetValue <CountryBM>();
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", countryBm);

            PersonBLL personBll = new PersonBLL();

            return(personBll.SavePerson(personBm));
        }
예제 #4
0
        public void CreateAddress()
        {
            //Prueba la creación de una dirección
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  countryBm  = result.GetValue <CountryBM>();
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", countryBm);

            ResultBM addressResult = addressBll.SaveAddress(addressBm);

            Assert.IsTrue(addressResult.IsValid(), "Debería haberse guardado");
        }
예제 #5
0
        public void CreateAddressFailsNumber()
        {
            //Prueba la validación del número
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  countryBm  = result.GetValue <CountryBM>();
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", -1, "Departamento", "Barrio", "Esta es una dirección creada mediante test", countryBm);

            ResultBM addressResult = addressBll.SaveAddress(addressBm);

            Assert.IsTrue(addressResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "No debería haber sido válido.");
            Assert.IsTrue(addressResult.description.Contains("calle"), "No debería haber sido válido.");
        }
예제 #6
0
        private PersonBM create_person()
        {
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  countryBm  = result.GetValue <CountryBM>();
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", countryBm);

            PersonBLL personBll  = new PersonBLL();
            PersonBM  personBm   = new PersonBM("Name test", "lastname test", DateTime.Now, "mail", "1553489636", 'M', 29192646, addressBm);
            ResultBM  saveResult = personBll.SavePerson(personBm);

            Assert.IsTrue(saveResult.IsValid(), "La persona debería haberse creado");
            return(saveResult.GetValue <PersonBM>());
        }
예제 #7
0
        private ResultBM IsValid(AddressBM addressBm)
        {
            if (addressBm.street == null || addressBm.street.Length == 0)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (STREET)"));
            }

            if (addressBm.number < 0)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("INVALID_VALUE_ERROR") + " (NUMBER < 0)"));
            }

            if (addressBm.country == null)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (COUNTRY)"));
            }

            return(new ResultBM(ResultBM.Type.OK));
        }
예제 #8
0
        public ResultBM UpdateAddress(AddressBM addressBm)
        {
            try
            {
                AddressDAL addressDal  = new AddressDAL();
                AddressDTO addressDto  = null;
                ResultBM   validResult = IsValid(addressBm);

                if (!validResult.IsValid())
                {
                    return(validResult);
                }
                addressDto = new AddressDTO(addressBm.id, addressBm.street, addressBm.number, addressBm.apartment, addressBm.neighborhood, addressBm.comment, addressBm.country.iso2);
                addressDal.UpdateAddress(addressDto);

                return(new ResultBM(ResultBM.Type.OK, "Dirección actualizada.", addressBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }
예제 #9
0
        /// <summary>
        /// Devuelve la dirección según el id informado por parámetro
        /// </summary>
        /// <param name="addressId"></param>
        /// <returns></returns>
        public ResultBM GetAddress(int addressId)
        {
            try
            {
                CountryBLL countryBll = new CountryBLL();
                AddressDAL addressDal = new AddressDAL();
                AddressDTO addressDto = addressDal.GetAddress(addressId);
                AddressBM  addressBm  = null;
                ResultBM   resultCountry;

                // Si la dirección existe, el país debería existir porque de otro modo no podría haberse dado de alta.
                if (addressDto != null)
                {
                    resultCountry = countryBll.GetCountry(addressDto.countryIso);

                    if (!resultCountry.IsValid())
                    {
                        return(resultCountry);
                    }
                    if (resultCountry.GetValue() != null)
                    {
                        addressBm = new AddressBM(addressDto, resultCountry.GetValue <CountryBM>());
                    }
                    else
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " countryIso " + addressDto.countryIso);
                    }
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", addressBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
예제 #10
0
        public ResultBM GetVolunteer(int volunteerId)
        {
            try {
                AddressBLL   addressBll    = new AddressBLL();
                ResultBM     addressResult = null;
                AddressBM    addressBm     = null;
                BranchBLL    branchBll     = new BranchBLL();
                ResultBM     branchResult  = null;
                BranchBM     branchBm      = null;
                UserBLL      userBll       = new UserBLL();
                ResultBM     userResult    = null;
                UserBM       userBm        = null;
                VolunteerDAL volunteerDal  = new VolunteerDAL();
                VolunteerBM  volunteerBm   = null;
                VolunteerDTO volunteerDto  = volunteerDal.GetVolunteer(volunteerId);

                if (volunteerDto != null)
                {
                    //Debería existir
                    addressResult = addressBll.GetAddress(volunteerDto.addressId);
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception("La dirección " + volunteerDto.addressId + " para el voluntario " + volunteerId + " no existe.");
                    }
                    addressBm = addressResult.GetValue <AddressBM>();

                    branchResult = branchBll.GetBranch(volunteerDto.branchId);
                    if (!branchResult.IsValid())
                    {
                        return(branchResult);
                    }
                    if (branchResult.GetValue() == null)
                    {
                        throw new Exception("La sede " + volunteerDto.branchId + " para el voluntario " + volunteerId + " no existe.");
                    }
                    branchBm = branchResult.GetValue <BranchBM>();

                    //El usuario podría no existir porque el voluntario no requiere necesariamente que se lo asocie
                    //con un susuario de sistema
                    userResult = userBll.GetUser(volunteerDto.userId);
                    if (!userResult.IsValid())
                    {
                        return(userResult);
                    }

                    if (userResult.GetValue() != null)
                    {
                        userBm = userResult.GetValue <UserBM>();
                    }

                    volunteerBm = new VolunteerBM(volunteerDto, addressBm, branchBm, userBm);
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", volunteerBm));
            }
            catch (Exception exception) {
                return(new ResultBM(ResultBM.Type.EXCEPTION, "Se ha producido un error al recuperar el voluntario " + volunteerId + ".", exception));
            }
        }