Ejemplo n.º 1
0
        public static bool DeleteAddressBL(int deleteAddressID)
        {
            bool AddressDeleted = false;

            try
            {
                if (deleteAddressID > 0)
                {
                    AddressDAL AddressDAL = new AddressDAL();
                    AddressDeleted = AddressDAL.DeleteAddressDAL(deleteAddressID);
                }
                else
                {
                    throw new AddressException("Invalid Address ID");
                }
            }
            catch (AddressException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(AddressDeleted);
        }
Ejemplo n.º 2
0
        public static AddressModel GetUserDefaultAddress(int UserID)
        {
            List <AddressModel> addresses = new List <AddressModel>();
            var reader = AddressDAL.SelectDefaultAddress(UserID);

            while (reader.Read())
            {
                AddressModel address = new AddressModel();
                address.id        = reader.GetInt32(0);
                address.tel       = reader.GetString(1);
                address.add       = reader.GetString(2);
                address.name      = reader.GetString(3);
                address.user_id   = reader.GetInt32(4);
                address.enabled   = reader.GetInt32(5);
                address.isdefault = reader.GetInt32(6);
                addresses.Add(address);
            }
            reader.Close();
            if (addresses.Count > 0)
            {
                return(addresses.First());
            }
            else
            {
                return(new AddressModel());
            }
        }
        public List <Address> GetShippingAdressByUserId(int userId)
        {
            var addressesShipping = new List <AddressDAL>();

            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("PS_GetShippingAddrsesByUserId", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@UserId", userId));
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        var addressShipping = new AddressDAL();
                        addressShipping.AddressId = (int)rdr["ShippingAddressId"];
                        addressShipping.Number    = (int)rdr["Number"];
                        addressShipping.Street    = (string)rdr["Street"];
                        addressShipping.ZipCode   = (int)rdr["ZipCode"];
                        addressShipping.City      = (string)rdr["City"];
                        addressShipping.Country   = (string)rdr["Country"];
                        addressShipping.IsDefault = (bool)rdr["IsDefault"];
                        addressesShipping.Add(addressShipping);
                    }
                }
            }
            List <Address> userAddressShipping = addressesShipping.Select(addressShipping => addressShipping.ToDomain()).ToList();

            return(userAddressShipping);
        }
Ejemplo n.º 4
0
 /// <see cref="AddressDAL.GetAddress(int)"/>
 public Address GetAddress(int id)
 {
     if (id < 1)
     {
         throw new ArgumentException("invalid id");
     }
     return(AddressDAL.GetAddress(id));
 }
Ejemplo n.º 5
0
 public static string SetDefaultAddress(AddressModel addressModel)
 {
     if (AddressDAL.UpdateDefaultAddress(addressModel.id) > 0)
     {
         return("设为默认收货地址成功");
     }
     return("设为默认收货地址失败");
 }
Ejemplo n.º 6
0
 public static string UpdateAddress(AddressModel addressModel)
 {
     if (AddressDAL.UpdateAddress(addressModel) > 0)
     {
         return("收货地址修改成功");
     }
     return("收货地址修改失败");
 }
 /// <summary>
 /// Invokes Serialize method of DAL.
 /// </summary>
 public void Serialize()
 {
     try
     {
         AddressDAL.Serialize();
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Updates a Patient's various records in the db
 /// </summary>
 /// <param name="person">Person of the patient to update</param>
 /// <param name="address">Address of the patient to update</param>
 /// <param name="patient">Patient to update</param>
 /// <returns></returns>
 public bool UpdatePatient(Person person, Address address, Patient patient)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         AddressDAL.UpdateAddress(address);
         PersonDAL.UpdatePerson(person);
         PatientDAL.UpdatePatient(patient);
         scope.Complete();
     }
     return(true);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Updates the given Nurse and their information in the db
 /// </summary>
 /// <param name="person">The Person of the Nurse to update</param>
 /// <param name="address">The Address of the Nurse to update</param>
 /// <param name="nurse">The Nurse to update</param>
 /// <returns>Whether or not the update succeeded</returns>
 public bool UpdateNurse(Person person, Address address, Nurse nurse)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         AddressDAL.UpdateAddress(address);
         PersonDAL.UpdatePerson(person);
         NurseDAL.UpdateNurse(nurse);
         scope.Complete();
     }
     return(true);
 }
Ejemplo n.º 10
0
 public static string DisableAddress(int id)
 {
     if (AddressDAL.UpdateAddressEnabled(id) > 0)
     {
         return("删除成功");
     }
     else
     {
         return("删除失败");
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 ///Invokes Deserialize method of DAL.
 /// </summary>
 public void Deserialize()
 {
     try
     {
         AddressDAL.Deserialize();
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 12
0
 public static string AddAdderss(AddressModel address)
 {
     if (AddressDAL.InsertAddress(address) == 0)
     {
         return("操作失败");
     }
     else
     {
         return("操作成功");
     }
 }
Ejemplo n.º 13
0
 public ActionResult AccountCreation(EmployeeVM employee)
 {
     EmployeeMap.CreateEmployee(employee);
     employee.EmployeeId     = EmployeeMap.GetEmployeeId(employee.EmployeeNumber);
     employee.Login.Email    = employee.Address.Email;
     employee.Login.Salt     = Convert.ToBase64String(Salt.GenerateSalt());
     employee.Login.Password = ORA_Data.Hash.GetHash(employee.Login.Password + employee.Login.Salt);
     LoginDAL.Register(Mapper.Map <LoginDM>(employee.Login), employee.EmployeeId);
     AddressDAL.CreateAddress(Mapper.Map <AddressDM>(employee.Address), employee.EmployeeId);
     Work_StatusDAL.CreateStatus(Mapper.Map <StatusDM>(employee.Status), employee.EmployeeId);
     TimeDAL.CreateEmptyTime(employee.EmployeeId);
     return(View());
 }
Ejemplo n.º 14
0
        internal static void OutputUserAddresses(UserDTO user, AddressDAL addresses)
        {
            var adr = addresses.GetByUserId(user.UserId);
            var str = $"\t{user.FirstName} {user.LastName}";

            TableHorizontalLength = 40;

            Console.Clear();
            Console.Write(str + '\n');
            OutputUnderline();

            adr.ForEach(a => { Console.WriteLine($" {a.City}, {a.Country}, {a.HouseNumber} {a.Street}"); });
            OutputUnderline();
        }
Ejemplo n.º 15
0
        public Boolean Insert(AddressENT entAddress)
        {
            AddressDAL dalAddress = new AddressDAL();

            if (dalAddress.Insert(entAddress))
            {
                return(true);
            }
            else
            {
                Message = dalAddress.Message;
                return(false);
            }
        }
Ejemplo n.º 16
0
        public Boolean Delete(SqlInt32 AddressID, SqlInt32 UserID)
        {
            AddressDAL dalAddress = new AddressDAL();

            if (dalAddress.Delete(AddressID, UserID))
            {
                return(true);
            }
            else
            {
                Message = dalAddress.Message;
                return(false);
            }
        }
Ejemplo n.º 17
0
        public Boolean Update(AddressENT entAddress, SqlInt32 AddressID, SqlInt32 UserID)
        {
            AddressDAL dalAddress = new AddressDAL();

            if (dalAddress.Update(entAddress, AddressID, UserID))
            {
                return(true);
            }
            else
            {
                Message = dalAddress.Message;
                return(false);
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Inserts a new Patient with their data into the db.
 /// </summary>
 /// <param name="patient">Person of Patient to insert</param>
 /// <param name="address">Address of Patient to insert</param>
 /// <returns>Whether or not the insertion succeeded</returns>
 public bool RegisterNurse(Person nurse, Address address)
 {
     if (nurse == null || address == null)
     {
         throw new ArgumentNullException("nurse and address cannot be null");
     }
     using (TransactionScope scope = new TransactionScope())
     {
         int?addressID = AddressDAL.InsertAddress(address);
         int?personID  = PersonDAL.InsertPerson(new Person(null, nurse.Username, nurse.Password, nurse.FirstName, nurse.LastName, nurse.DateOfBirth,
                                                           nurse.SSN, nurse.Gender, addressID, nurse.ContactPhone));
         NurseDAL.InsertNurse(new Nurse(null, personID, true));
         scope.Complete();
     }
     return(true);
 }
Ejemplo n.º 19
0
        public static Address SearchAddressBL(int searchAddressID)
        {
            Address searchAddress = null;

            try
            {
                AddressDAL AddressDAL = new AddressDAL();
                searchAddress = AddressDAL.SearchAddressDAL(searchAddressID);
            }
            catch (AddressException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(searchAddress);
        }
Ejemplo n.º 20
0
        public static List <Address> GetAllAddresssBL()
        {
            List <Address> AddressList = null;

            try
            {
                AddressDAL AddressDAL = new AddressDAL();
                AddressList = AddressDAL.GetAllAddressDAL();
            }
            catch (AddressException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(AddressList);
        }
Ejemplo n.º 21
0
        public static List <AddressModel> GetAddressesByUserID(int id)
        {
            List <AddressModel> addresses = new List <AddressModel>();
            var reader = AddressDAL.SelectAddressByUserID(id);

            while (reader.Read())
            {
                AddressModel address = new AddressModel();
                address.id        = reader.GetInt32(0);
                address.tel       = reader.GetString(1);
                address.add       = reader.GetString(2);
                address.name      = reader.GetString(3);
                address.user_id   = reader.GetInt32(4);
                address.enabled   = reader.GetInt32(5);
                address.isdefault = reader.GetInt32(6);
                addresses.Add(address);
            }
            reader.Close();
            return(addresses);
        }
Ejemplo n.º 22
0
        public static AddressModel GetAddressByID(int id)
        {
            AddressModel address = new AddressModel();
            var          reader  = AddressDAL.SelectAddressByID(id);

            if (reader == null)
            {
                return(address);
            }
            reader.Read();
            address.id        = reader.GetInt32(0);
            address.tel       = reader.GetString(1);
            address.add       = reader.GetString(2);
            address.name      = reader.GetString(3);
            address.user_id   = reader.GetInt32(4);
            address.enabled   = reader.GetInt32(5);
            address.isdefault = reader.GetInt32(6);
            reader.Close();
            return(address);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Inserts a new Patient with their data into the db.
 /// </summary>
 /// <param name="patient">Person of Patient to insert</param>
 /// <param name="address">Address of Patient to insert</param>
 /// <returns>Whether or not the insertion succeeded</returns>
 public bool RegisterPatient(Person patient, Address address)
 {
     if (patient == null || address == null)
     {
         throw new ArgumentNullException("patient and address cannot be null");
     }
     if (patient.Username != null || patient.Password != null)
     {
         throw new ArgumentNullException("username and password of a patient should be null");
     }
     using (TransactionScope scope = new TransactionScope())
     {
         int?addressID = AddressDAL.InsertAddress(address);
         int?personID  = PersonDAL.InsertPerson(new Person(null, null, null, patient.FirstName, patient.LastName, patient.DateOfBirth,
                                                           patient.SSN, patient.Gender, addressID, patient.ContactPhone));
         PatientDAL.InsertPatient(new Patient(null, personID, true));
         scope.Complete();
     }
     return(true);
 }
Ejemplo n.º 24
0
        internal static void OutputUsers(UserDAL users, AddressDAL addresses, string sortingKey = "UserId", string orderBy = "a")
        {
            List <UserDTO> u = null;

            if (orderBy == "a")
            {
                u = users.Get().OrderBy(s => s.GetType()?.GetProperty(sortingKey)?.GetValue(s)).ToList();
            }
            else
            {
                u = users.Get().OrderByDescending(s => s.GetType()?.GetProperty(sortingKey)?.GetValue(s)).ToList();
            }

            foreach (var user in u)
            {
                var adr = addresses.GetByUserId(user.UserId);
                OutputUser(user, adr.FirstOrDefault());
            }

            OutputUnderline();
        }
Ejemplo n.º 25
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));
            }
        }
Ejemplo n.º 26
0
        static void PrintCountries()
        {
            string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            string fileName    = "authors.xlsx";

            Console.WriteLine("Input Address city");
            var city             = Console.ReadLine().ToString();
            var AddressDAL       = new AddressDAL(_iconfiguration);
            var listAddressModel = AddressDAL.GetList(city);

            Console.WriteLine("Your city adress is:");

            listAddressModel.ForEach(item =>
            {
                Console.WriteLine($"Your address is: {item.AddressLine1}");
            });
            using (var wb = new ClosedXML.Excel.XLWorkbook())
            {
                var ws         = wb.AddWorksheet("Duy");
                var currentRow = 1;
                ws.Cell(currentRow, 1).SetValue("Id");
                ws.Cell(currentRow, 2).SetValue("Address");
                ws.Cell(currentRow, 3).SetValue("City");

                foreach (var item in listAddressModel)
                {
                    currentRow++;
                    ws.Cell(currentRow, 1).SetValue(item.AddressId);
                    ws.Cell(currentRow, 2).SetValue(item.AddressLine1);
                    ws.Cell(currentRow, 3).SetValue(item.City);
                }
                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string savePath    = Path.Combine(desktopPath, "test.xlsx");
                wb.SaveAs(savePath, false);
            }

            Console.WriteLine("Press any key to stop.");
            Console.ReadKey();
        }
Ejemplo n.º 27
0
        public static bool AddAddressBL(Address newAddress)
        {
            bool AddressAdded = false;

            try
            {
                if (ValidateAddress(newAddress))
                {
                    AddressDAL AddressDAL = new AddressDAL();
                    AddressAdded = AddressDAL.AddAddressDAL(newAddress);
                }
            }
            catch (AddressException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(AddressAdded);
        }
Ejemplo n.º 28
0
        public static bool UpdateAddressBL(Address updateAddress)
        {
            bool AddressUpdated = false;

            try
            {
                if (ValidateAddress(updateAddress))
                {
                    AddressDAL AddressDAL = new AddressDAL();
                    AddressUpdated = AddressDAL.UpdateAddress(updateAddress);
                }
            }
            catch (AddressPhoneBookException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(AddressUpdated);
        }
Ejemplo n.º 29
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));
            }
        }
Ejemplo n.º 30
0
 public AddressBO()
 {
     addressDAL = new AddressDAL();
 }