Exemple #1
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);
        }
Exemple #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;
            }
        }
Exemple #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;
                }
            }
        }