Ejemplo n.º 1
0
        public static async Task <string> GenerateShipmentID(Models.Shipment data, ShipmentDBContext _contex)
        {
            bool   existsCheck;
            string currentID;
            string generatedID;

            try
            {
                existsCheck = (_contex.Shipments
                               .Where(a => a.ClientID == data.ClientID)
                               .OrderByDescending(a => a.ShipmentID)).Count() > 0;
                if (existsCheck)
                {
                    currentID = (await _contex.Shipments
                                 .Where(a => a.ClientID == data.ClientID)
                                 .OrderByDescending(a => a.ShipmentID)
                                 .FirstAsync()).ShipmentID;
                    generatedID = (Convert.ToInt64(currentID) + 1).ToString();
                }
                else
                {
                    generatedID = data.ClientID.ToString() + "00000000001";
                }
                return(generatedID);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public static async Task <bool> DeleteUser(UserLogin data, ShipmentDBContext _context)
        {
            try
            {
                bool HashValidity = await AuthenticateClient(data, _context);

                if (HashValidity)
                {
                    var Client = await _context.ClientAuths.Where(a => a.NAME == data.Name).FirstAsync();

                    _context.Remove(Client);
                    await _context.SaveChangesAsync();
                }
                return(HashValidity);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public static async Task <ClientAuth> RegisterClient(UserLogin data, ShipmentDBContext _context)
        {
            bool checkUnique;

            Models.ClientAuth client;
            int currentClientID;

            checkUnique = _context.ClientAuths
                          .Where(a => a.NAME == data.Name)
                          .Count() > 0;
            if (checkUnique)
            {
                throw new Exception("Client name must be unique.");
            }
            else
            {
                try
                {
                    currentClientID = (await _context.ClientAuths
                                       .OrderByDescending(a => a.ID)
                                       .FirstAsync()).ID;

                    (string hash, string salt) = GenerateSaltAndHash(data.Password);
                    client = new Models.ClientAuth()
                    {
                        ID   = currentClientID + 1,
                        SALT = salt,
                        HASH = hash,
                        NAME = data.Name
                    };
                    _context.ClientAuths.Add(client);
                    await _context.SaveChangesAsync();

                    return(client);
                }
                catch (System.Exception ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 4
0
        public static async Task <bool> AuthenticateClient(UserLogin data, ShipmentDBContext _context)
        {
            try
            {
                var Client = await _context.ClientAuths.Where(a => a.NAME == data.Name).FirstAsync();

                var HashValidity = LoginAndRegistration.CompareHash(data.Password, Client);
                if (!HashValidity)
                {
                    throw new Exception("Invalid password.");
                }
                else
                {
                    return(HashValidity);
                }
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
 public UserController(ShipmentDBContext shipmentDBContext)
 {
     _shipmentDBContext = shipmentDBContext;
 }
Ejemplo n.º 6
0
        public static async Task <Models.Shipment> CreateShipment(Models.Shipment data, ShipmentDBContext _contex)
        {
            data.ShipmentID = await ShipmentMaster.GenerateShipmentID(data, _contex);

            await _contex.Shipments.AddAsync(data);

            await _contex.SaveChangesAsync();

            return(data);
        }