public bool SubtractStockLeft(decimal stockAmount, long productID)
        {
            decimal stockLeft = Convert.ToDecimal(StockLeftByProduct(productID));

            if (stockLeft >= stockAmount)
            {
                using (var _context = new SalesTrackingSystemEntities())
                {
                    decimal newFistbatchStockLeft;
                    var     FirstBatchdata = (from batch in _context.Batches.Where(batch => batch.ProductID == productID && batch.StockLeft != 0)
                                              select new Batch_Model()
                    {
                        BatchID = batch.BatchID,
                        StockLeft = batch.StockLeft,
                    }).FirstOrDefault();
                    if (FirstBatchdata.StockLeft >= stockAmount)
                    {
                        newFistbatchStockLeft = Convert.ToDecimal(FirstBatchdata.StockLeft) - stockAmount;
                        var data = _context.Batches.Where(batch => batch.BatchID == FirstBatchdata.BatchID).FirstOrDefault();
                        data.StockLeft   = newFistbatchStockLeft;
                        data.DateUpdated = DateTime.Now;
                        _context.SaveChanges();
                    }
                    else
                    {
                        newFistbatchStockLeft = Convert.ToDecimal(FirstBatchdata.StockLeft) - stockAmount;
                        var data = _context.Batches.Where(batch => batch.BatchID == FirstBatchdata.BatchID).FirstOrDefault();
                        data.StockLeft   = newFistbatchStockLeft;
                        data.DateUpdated = DateTime.Now;
                        _context.SaveChanges();

                        var SecondtBatchdata = (from batch in _context.Batches.Where(batch => batch.ProductID == productID && batch.StockLeft != 0)
                                                select new Batch_Model()
                        {
                            BatchID = batch.BatchID,
                            StockLeft = batch.StockLeft,
                        }).FirstOrDefault();
                        var newSecondbatchStockLeft = Convert.ToDecimal(FirstBatchdata.StockLeft) - newFistbatchStockLeft;
                        var SecondData = _context.Batches.Where(batch => batch.BatchID == SecondtBatchdata.BatchID).FirstOrDefault();
                        data.StockLeft   = newSecondbatchStockLeft;
                        data.DateUpdated = DateTime.Now;
                        _context.SaveChanges();
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 public bool Save(Products_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new Product()
             {
                 ProductID         = GetNewProductID(),
                 ProductCategoryID = model.ProductCategoryID,
                 ProductName       = model.ProductName,
                 PackRate          = model.PackRate,
                 UnitId            = model.UnitId,
                 Description       = model.Description,
                 DateCreated       = DateTime.Now
             };
             _context.Products.Add(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Exemplo n.º 3
0
 public bool Save(DistributorArea_Model distArea)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new DistributorArea()
             {
                 DistributorAreaID = GetNewDistributorAreaID(),
                 DistrubitorID     = distArea.DistrubitorID,
                 City        = distArea.City,
                 State       = distArea.State,
                 District    = distArea.District,
                 Address     = distArea.Address,
                 Latitude    = distArea.Latitude,
                 Longitude   = distArea.Longitude,
                 DateCreated = DateTime.Now
             };
             _context.DistributorAreas.Add(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public bool Save(Batch_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new Batch()
             {
                 BatchID           = GetNewBatchID(),
                 BatchName         = model.BatchName,
                 ProductCategoryId = model.ProductCategoryId,
                 ProductID         = model.ProductID,
                 QunatityProduced  = model.QunatityProduced,
                 UnitPrice         = model.UnitPrice,
                 StockLeft         = Convert.ToInt64(model.QunatityProduced),
                 DateProduced      = model.DateProduced,
                 ExpiryDate        = model.ExpiryDate,
                 DateCreated       = DateTime.Now
             };
             _context.Batches.Add(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Exemplo n.º 5
0
 public bool Update(DistributorArea_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.DistributorAreas.Where(distArea => distArea.DistributorAreaID == model.DistributorAreaID).FirstOrDefault();
             data.DistributorAreaID = model.DistributorAreaID;
             data.DistrubitorID     = model.DistrubitorID;
             data.State             = model.State;
             data.District          = model.District;
             data.City        = model.City;
             data.Address     = model.Address;
             data.Latitude    = model.Latitude;
             data.Longitude   = model.Longitude;
             data.DateUpdated = DateTime.Now;
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
             //throw;
         }
     }
 }
        public bool UpdateUserAccount(Users_Model users_Model)
        {
            using (var _dbContext = new SalesTrackingSystemEntities())
            {
                try
                {
                    var data = _dbContext.Users.Where(act => act.UserID == users_Model.UserID).FirstOrDefault();
                    data.UserProfileID = users_Model.UserProfileID;
                    data.DistrubitorID = users_Model.DistrubitorID;
                    data.FullName      = users_Model.FullName;
                    data.MobileNo      = users_Model.MobileNo;
                    if (users_Model.ImageString != null)
                    {
                        data.ImageString = users_Model.ImageString;
                    }
                    data.UsersStatus = users_Model.UsersStatus;

                    _dbContext.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
 public bool Update(Batch_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Batches.Where(batch => batch.BatchID == model.BatchID).FirstOrDefault();
             data.BatchName         = model.BatchName;
             data.ProductCategoryId = model.ProductCategoryId;
             data.ProductID         = model.ProductID;
             data.QunatityProduced  = model.QunatityProduced;
             data.UnitPrice         = model.UnitPrice;
             data.StockLeft         = model.StockLeft;
             data.DateProduced      = model.DateProduced;
             data.ExpiryDate        = model.ExpiryDate;
             data.DateUpdated       = DateTime.Now;
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool SaveUserProfileDetails(UserProfileDetails_Model userProfileDetails)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new UserProfileDetail()
             {
                 UserProfileDetailID = userProfileDetails.UserProfileDetailID,
                 UserProfileID       = userProfileDetails.UserProfileID,
                 ModuleID            = userProfileDetails.ModuleID,
                 ModuleActionID      = userProfileDetails.ModuleActionID,
                 ProfileDetailStatus = userProfileDetails.ProfileDetailStatus,
                 Description         = userProfileDetails.Description,
                 CreatedBy           = userProfileDetails.CreatedBy,
                 DateCreated         = DateTime.Now
             };
             _dbContext.UserProfileDetails.Add(data);
             _dbContext.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool Update(Distributor_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Distributors.Where(dist => dist.DistrubitorID == model.DistrubitorID).FirstOrDefault();
             data.DistrubitorID   = model.DistrubitorID;
             data.DistrubitorName = model.DistrubitorName;
             data.OwnerName       = model.OwnerName;
             data.RegestrationID  = model.RegestrationID;
             data.MobileNo        = model.MobileNo;
             data.Phone           = model.Phone;
             data.Fax             = model.Fax;
             data.Email           = model.Email;
             data.State           = model.State;
             data.District        = model.District;
             data.Address         = model.Address;
             data.Latitude        = model.Latitude;
             data.Longitude       = model.Longitude;
             data.DateUpdated     = DateTime.Now;
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 10
0
 public Int64 SaveTransaction(Transaction_Model transaction)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new Transaction()
             {
                 TransactionID    = GetNewTransactionID(),
                 TransactionLevel = transaction.TransactionLevel,
                 SupplierID       = transaction.SupplierID,
                 ReceiverID       = transaction.ReceiverID,
                 InvoiceNo        = transaction.InvoiceNo,
                 InvoiceDate      = transaction.InvoiceDate,
                 InvoiceEntryDate = DateTime.Now,
                 DiscountPercent  = transaction.DiscountPercent,
                 TaxPercent       = transaction.TaxPercent,
                 DateCreated      = DateTime.Now
             };
             _dbContext.Transactions.Add(data);
             _dbContext.SaveChanges();
             var transactionID = data.TransactionID;
             return(transactionID);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public bool Save(Distributor_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new Distributor()
             {
                 DistrubitorID   = GetNewDistributorID(),
                 DistrubitorName = model.DistrubitorName,
                 OwnerName       = model.OwnerName,
                 RegestrationID  = model.RegestrationID,
                 MobileNo        = model.MobileNo,
                 Phone           = model.Phone,
                 Fax             = model.Fax,
                 Email           = model.Email,
                 State           = model.State,
                 District        = model.District,
                 Address         = model.Address,
                 Latitude        = model.Latitude,
                 Longitude       = model.Longitude,
                 DateCreated     = DateTime.Now
             };
             _context.Distributors.Add(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Exemplo n.º 12
0
 public bool Save(Reseller_Model res)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new Reseller()
             {
                 ResellerID     = GetNewResellerId(),
                 ResellerName   = res.ResellerName,
                 OwnerName      = res.OwnerName,
                 RegestrationID = res.RegestrationID,
                 DistrubitorID  = res.DistrubitorID,
                 Mobile         = res.Mobile,
                 Phone          = res.Phone,
                 Email          = res.Email,
                 State          = res.State,
                 District       = res.District,
                 Address        = res.Address,
                 Latitude       = res.Latitude,
                 Longitude      = res.Longitude,
                 DateCreated    = DateTime.Now
             };
             _context.Resellers.Add(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Exemplo n.º 13
0
 public bool Update(Reseller_Model res)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Resellers.Where(reseller => reseller.ResellerID == res.ResellerID).FirstOrDefault();
             data.ResellerID     = res.ResellerID;
             data.ResellerName   = res.ResellerName;
             data.OwnerName      = res.OwnerName;
             data.RegestrationID = res.RegestrationID;
             data.DistrubitorID  = res.DistrubitorID;
             data.Mobile         = res.Mobile;
             data.Phone          = res.Phone;
             data.Email          = res.Email;
             data.State          = res.State;
             data.District       = res.District;
             data.Address        = res.Address;
             data.Latitude       = res.Latitude;
             data.Longitude      = res.Longitude;
             data.DateUpdated    = DateTime.Now;
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public bool SaveUserAccount(Users_Model users_Model)
 {
     using (var db_Context = new SalesTrackingSystemEntities())
     {
         using (DbContextTransaction db = db_Context.Database.BeginTransaction())
         {
             try
             {
                 var UserData = new User()
                 {
                     UserID        = GetNewUserId(),
                     UserProfileID = users_Model.UserProfileID,
                     FullName      = users_Model.FullName,
                     PasswordHash  = users_Model.PasswordHash,
                     Email         = users_Model.Email,
                     MobileNo      = users_Model.MobileNo,
                     ImageString   = users_Model.ImageString,
                     UsersStatus   = users_Model.UsersStatus,
                     DateCreated   = DateTime.Now
                 };
                 db_Context.Users.Add(UserData);
                 db_Context.SaveChanges();
                 var userId = UserData.UserID;
                 Verification_Interface verification_ = new Verification_service();
                 var DataVarification = new Verification()
                 {
                     VerificationID = verification_.GetNewVerificationId(),
                     UserID         = userId,
                     IsVerified     = false,
                     DateCreated    = DateTime.Now
                 };
                 db_Context.Verifications.Add(DataVarification);
                 db_Context.SaveChanges();
                 db.Commit();
                 return(true);
             }
             catch (DbEntityValidationException)
             {
                 db.Rollback();
                 return(false);
             }
         }
     }
 }
Exemplo n.º 15
0
 public bool Delete(long ResellerId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Resellers.Where(res => res.ResellerID == ResellerId).FirstOrDefault();
             _context.Resellers.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool DeleteUserProfileDetails(long userProfileDetailsId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.UserProfileDetails.Where(userProfileDetails => userProfileDetails.UserProfileDetailID == userProfileDetailsId).FirstOrDefault();
             _context.UserProfileDetails.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 17
0
 public bool DeleteModule(long moduleId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Modules.Where(ModuleActions => ModuleActions.ModuleID == moduleId).FirstOrDefault();
             _context.Modules.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool updateCheckedVerification(long userId, byte isVerified)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _dbContext.Verifications.Where(verificationAction => verificationAction.UserID == userId).FirstOrDefault();
             data.IsVerified = Convert.ToBoolean(isVerified);
             _dbContext.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public Users_Model UpdateOnLogin(string email, string password, string token = null, int status = 1)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _dbContext.Users.Where(actionUser => actionUser.Email == email && actionUser.PasswordHash == password).FirstOrDefault();
             data.Token       = token;
             data.UsersStatus = status;
             _dbContext.SaveChanges();
             var returnData = (from actionUser in _dbContext.Users.Where(actionUser => actionUser.Email == email && actionUser.PasswordHash == password)
                               join actionUserProfile in _dbContext.UserProfiles on actionUser.UserProfileID equals actionUserProfile.UserProfileID
                               join actionVericication in _dbContext.Verifications on actionUser.UserID equals actionVericication.UserID
                               select new Users_Model()
             {
                 UserID = actionUser.UserID,
                 UserProfileID = actionUserProfile.UserProfileID,
                 DistrubitorID = actionUser.DistrubitorID,
                 FullName = actionUser.FullName,
                 PasswordHash = actionUser.PasswordHash,
                 Email = actionUser.Email,
                 Token = actionUser.Token,
                 MobileNo = actionUser.MobileNo,
                 ImageString = actionUser.ImageString,
                 UsersStatus = actionUser.UsersStatus,
                 ProfileName = actionUserProfile.ProfileName,
                 Description = actionUserProfile.Description,
                 CreatedBy = actionUserProfile.CreatedBy,
                 UserProfileStatus = actionUserProfile.UserProfileStatus,
                 VerificationID = actionVericication.VerificationID,
                 IsVerified = actionVericication.IsVerified,
                 VerifiedToken = actionVericication.VerifiedToken,
                 DateVerified = actionVericication.DateVerified,
                 ResetToken = actionVericication.ResetToken,
                 ResetTriggered = actionVericication.ResetTriggered,
                 DateCreated = actionUser.DateCreated,
                 DateUpdated = actionUser.DateUpdated
             }).FirstOrDefault();
             return(returnData);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
 public bool MakeDistrubitorNull(long userId)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _dbContext.Users.Where(a => a.UserID == userId).FirstOrDefault();
             data.DistrubitorID = null;
             _dbContext.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool Delete(long DistributorId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Distributors.Where(dist => dist.DistrubitorID == DistributorId).FirstOrDefault();
             _context.Distributors.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool Delete(long unitID)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Units.Where(dist => dist.UnitId == unitID).FirstOrDefault();
             _context.Units.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 23
0
 public bool Delete(long ProductId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Products.Where(prod => prod.ProductID == ProductId).FirstOrDefault();
             _context.Products.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 24
0
 public bool DeleteDashboardTable(long DashboardTableId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.DashboardTables.Where(dashboardTable => dashboardTable.DashboardTableId == DashboardTableId).FirstOrDefault();
             _context.DashboardTables.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 25
0
 public bool DeleteDashboardGivenColumn(long GivenColumnId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.DashboardGivenColumns.Where(GivenColumns => GivenColumns.DashboardGivenColumnId == GivenColumnId).FirstOrDefault();
             _context.DashboardGivenColumns.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool DeleteVerification(long userId)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Verifications.Where(act => act.UserID == userId).FirstOrDefault();
             _context.Verifications.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Exemplo n.º 27
0
 public bool DeleteTransaction(long TransactionID)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Transactions.Where(trans => trans.TransactionID == TransactionID).FirstOrDefault();
             _context.Transactions.Remove(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool updateResetAuthentication(Int64 userId, DateTime dateTriggered, string resetToken)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _dbContext.Verifications.Where(verificationAction => verificationAction.UserID == userId).FirstOrDefault();
             data.ResetTriggered = dateTriggered;
             data.ResetToken     = resetToken;
             _dbContext.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool UpdateOnLogout(string email, string password, string token = null, int status = 2)
 {
     using (var _dbContext = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _dbContext.Users.Where(a => a.Email == email && a.PasswordHash == password).FirstOrDefault();
             data.Token       = token;
             data.UsersStatus = status;
             _dbContext.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 30
0
 public bool UpateBalance(decimal balance, long transactionID)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Transactions.Where(trans => trans.TransactionID == transactionID).FirstOrDefault();
             data.Balance     = balance;
             data.DateUpdated = DateTime.Now;
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }