public void Refresh(int userId)
 {
     this.CurrentUser = repository.Users.FindBy(u => u.UserID == userId).SingleOrDefault();
     loadlookup();
     //var viewmodel = new PermissionListViewModel(this.CurrentUser.Permissions.ToList());
     //permissionbindingSource.DataSource = viewmodel.Permissions;
 }
        public void CreateDetailTransactionsForErrorCorrection(Order order, BLL.PickList picklist,
                                        Issue stvLog, int receiptPalletId, int receiptID, User user, DateTime convertedEthDate
                                        , int newItemId, int newUnitId, int newManufacturerId, decimal pickedPack
                                        , decimal Convertedpack, int confirmationStatusId, bool changeExpiryDate
                                        , DateTime? ExpiryDate, bool changeBatchNo, string batchNo)
        {
            //Load the ReceivePallet First From that we Get the Information that We need
            ReceivePallet receivePalletOriginal = new ReceivePallet();
            receivePalletOriginal.LoadByPrimaryKey(receiptPalletId);

            ReceiveDoc receiveDocOriginal = new ReceiveDoc();
            receiveDocOriginal.LoadByPrimaryKey(receivePalletOriginal.ReceiveID);

            //Load ItemUnit Detail for For ItemUnit Change;
            ItemUnit newItemUnit = new ItemUnit();
            newItemUnit.LoadByPrimaryKey(newUnitId);

              // Generate PicklistDetail With OrderDetail information
            PickListService pickListService = new PickListService();
            PickListDetail pickListDetail = pickListService.CreatePicklistDetailWithOrder(receiveDocOriginal, receivePalletOriginal, order, picklist,
                                                          pickedPack);
            // Generate IssueDoc from picklistDetail and substract the quantity from receiveDoc
            IssueService issueService = new IssueService();
            issueService.CreateIssueFromPicklist(pickListDetail, order, convertedEthDate, stvLog, user);

            if (Convertedpack > 0)
            {
                //duplicate The ReceiveDoc and ReceiptPallet
                ReceiveService receiveService = new ReceiveService();
                receiveService.CloneReceiveForErrorCorrection(confirmationStatusId, receivePalletOriginal, receiveDocOriginal
                                                                , Convertedpack, user, newItemId
                                                                , receiveDocOriginal.StoreID, receiptID
                                                                , newManufacturerId, newItemUnit, convertedEthDate,changeExpiryDate,ExpiryDate,changeBatchNo,batchNo);
            }
        }
 private void LoadUser()
 {
     CurrentUser = repository.Users.FindBy(u => u.UserID == _userID).FirstOrDefault();
     fromFullName.Text = CurrentUser.FullName;
     fromUserName.Text = CurrentUser.UserName;
     fromLastLogin.Text = (CurrentUser.LastLogin == null)?"":CurrentUser.LastLogin.ToString();
     lkAlternatives.Properties.DataSource = repository.Users.FindBy(u => u.UserID != _userID && u.IsActive == true).OrderBy(u=>u.UserName).ToList();
 }
        public int CreateTransactionForErrorCorrection(DataView dataView, int newItemId, int newUnitId, int newManufacturerId, decimal ConversionFactor, string Remark, DateTime convertedEthDate, int userId, bool changeExpiryDate = false, DateTime? ExpiryDate = null, bool changeBatchNo = false, string batchNo = null)
        {
            //Last Validation
            if (dataView.Count == 0)
            {
                throw new Exception("DataView is empty, the Error correction cannot be commited");
            }
            //User Information
            User user = new User();
            user.LoadByPrimaryKey(userId);

            var stvLog = new Issue();
            Order order;
            PickList picklist;

            //The First ReceiveDoc entry on the It Holds enough Informa
            var firstReceiveDoc = new ReceiveDoc();
            firstReceiveDoc.LoadByPrimaryKey(Convert.ToInt32(dataView[0]["ReceiveDocID"]));
            int activityId = firstReceiveDoc.StoreID;

            stvLog = HandleTransferBeforeReceipt(user,activityId, out order, out picklist);

            var listOfWarehouse = new List<int>();
            foreach (DataRow rw in dataView.Table.Rows)
            {
                if (!listOfWarehouse.Contains(Convert.ToInt32(rw["WearehouseID"])))
                {
                    listOfWarehouse.Add(Convert.ToInt32(rw["WearehouseID"]));
                }
            }

            foreach (var wearehouse in listOfWarehouse)
            {
                dataView.RowFilter = String.Format("WearehouseID = {0}", wearehouse);
                DataView singleWearehouseDataView = dataView;
                HandleTransferForSingleWearehouse(wearehouse,singleWearehouseDataView, newItemId, newUnitId, newManufacturerId, ConversionFactor, Remark, convertedEthDate, user, changeExpiryDate, ExpiryDate, changeBatchNo, batchNo,activityId,stvLog,order,picklist);
                dataView.RowFilter = string.Empty;
            }

            return stvLog.IDPrinted;
        }
        public UserViewModel(User user)
        {
            UserID = user.UserID;
            Username = user.UserName;
            if (user.AccountUsers != null)
            {
                //Accounts = (from au in user.AccountUsers.Where(u => u.IsActive) select au.Account).ToList();
                //Stores = (from su in user.StoreUsers.Where(u => u.IsActive) select su.Store).ToList();
               // Groups = (from ug in user.UserGroups select ug.Group).ToList();
                //Permissions = user.Permissions.ToList();
            }

            FirstName = user.FirstName;
            LastName = user.LastName;
            IsActive = user.IsActive;
            LastLogin = Convert.ToDateTime(user.LastLogin);
            Password = user.Password;
            DepartmentID = user.DepartmentID;
            JobTitleID = user.JobTitleID;
            CreatedDate = Convert.ToDateTime(user.CreatedDate);
            ModifiedDate = Convert.ToDateTime(user.ModifiedDate);
            if (user.PasswordExpires != null) PasswordExpires = (bool) user.PasswordExpires;
            ExpirationDate = Convert.ToDateTime(user.ExpirationDate);
        }
        private void HandleTransferForSingleWearehouse(int wearehouse, DataView dataView, int newItemId, int newUnitId, int newManufacturerId,
                                                        decimal ConversionFactor, string Remark, DateTime convertedEthDate,
                                                        User user, bool changeExpiryDate, DateTime? ExpiryDate,
                                                        bool changeBatchNo, string batchNo, int activityId, Issue stvLog, Order order, PickList picklist)
        {
            int  receiptTypeID = ReceiptType.CONSTANTS.ERROR_CORRECTION;

            ReceiveService receiveService = new ReceiveService();

            Receipt receipt = receiveService.CreateFakeReceiptWithInvoicePO(order.OrderTypeID, activityId,GeneralInfo.Current.SupplierID,
                                                                            Remark,
                                                                            stvLog.IDPrinted,
                                                                            receiptTypeID,
                                                                            user.ID, BLL.Settings.IsVaccine ? ReceiptConfirmationStatus.Constants.GRV_PRINTED : ReceiptConfirmationStatus.Constants.GRNF_PRINTED, wearehouse);

            //Loop throw the Dataview and Create Detail Transaction
            foreach (DataRowView dataRowView in dataView)
            {
                int receivePalletID = Convert.ToInt32(dataRowView["receivePalletId"]);
                decimal pack = Convert.ToDecimal(dataRowView["PickedQty"]);
                decimal convertedPack = Convert.ToDecimal(pack*Convert.ToDecimal(ConversionFactor));

                if (pack != 0)
                {
                    CreateDetailTransactionsForErrorCorrection(order, picklist, stvLog, receivePalletID, receipt.ID,
                                                               user, convertedEthDate, newItemId, newUnitId,
                                                               newManufacturerId, pack, convertedPack,
                                                               ReceiptConfirmationStatus.Constants.GRNF_PRINTED,
                                                               changeExpiryDate, ExpiryDate, changeBatchNo, batchNo);
                }
            }

            ErrorCorrection.Log(stvLog, receipt, ConversionFactor);
        }
        private Issue HandleTransferBeforeReceipt(User user, int activityId,out Order order,out PickList picklist)
        {
            int orderType = OrderType.CONSTANTS.ERROR_CORRECTION_TRANSFER;
            int paymentType = PaymentType.Constants.ERROR_CORRECTION;
            int orderStatus = OrderStatus.Constant.ISSUED;

            order = Order.GenerateOrder(null, orderType,
                                        orderStatus, activityId,
                                        paymentType, user.FullName,GeneralInfo.Current.InstitutionID, user.ID, 0);

            picklist = PickList.GeneratePickList(order.ID);

            var issueService = new IssueService();
            return issueService.CreateSTVLog(null, false, picklist, order, null, activityId, false, user.ID);
        }
 public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status)
 {
     if (_repository.FindBy(u => u.Username == username).FirstOrDefault() == null)
     {
         status = MembershipCreateStatus.InvalidUserName;
         return null;
     }
     var user = new User
                    {
                        Username = username,
                    };
     user.SetPassword(password);
     _repository.Add(user);
     status = MembershipCreateStatus.Success;
     return GetUser(username,true);
 }
        private void Refresh(int userId)
        {
            repository.RefreshContext();
            CurrentUser = repository.Users.FindBy(u => u.UserID == userId).SingleOrDefault();
            currentUserBindingSource.DataSource = CurrentUser;
            if (CurrentUser != null)
            {
                //repository.Dispose();
                //repository = new UnitOfWork();

                CurrentUser = repository.Users.FindBy(u => u.UserID == userId).SingleOrDefault();
                currentUserBindingSource.DataSource = CurrentUser;
                Accounts = (from au in CurrentUser.AccountUsers.Where(u => u.IsActive && u.Account.SubAccount != null) select au.Account).OrderBy(o=>o.FullName).ToList();
                Stores = (from us in CurrentUser.StoreUsers.Where(u => u.IsActive) select us.Store).Where(o=>o.Warehouse != null).OrderBy(o=>o.FullName).ToList();
                Groups = (from ug in CurrentUser.UserGroups.Where(u => u.GroupStatus == true) select ug.Group).ToList();

                NewMode = false;

                deptbindingSource.DataSource = CurrentUser.Department;
                jobtitlebindingSource.DataSource = CurrentUser.JobTitle;

                // This is edit
                btnSetPassword.Enabled = true;
                btnClose.Enabled = true;
                btnDisable.Enabled = true;
                btnAddStore.Enabled = true;
                btnAddGroup.Enabled = true;
                btnAddAccount.Enabled = true;
                btnRemoveAccount.Enabled = true;
                btnRemoveGroup.Enabled = true;
                btnRemoveStore.Enabled = true;
                passwordtextEdit.Enabled = false;
                btnSetPassword.Enabled = true;
                isActiveCheckEdit.Enabled = false;
                Loadlookups();
                btnSaveUserDetail.Enabled = true;
                NewMode = false;
                Text = @"Edit User";

                _username = CurrentUser.UserName;
            }else
            {
                NewMode = true;
                btnSetPassword.Enabled = false;
                btnClose.Enabled = false;
                btnDisable.Enabled = false;
                btnAddStore.Enabled = false;
                btnAddGroup.Enabled = false;
                btnAddAccount.Enabled = false;
                btnRemoveAccount.Enabled = false;
                btnRemoveGroup.Enabled = false;
                btnRemoveStore.Enabled = false;
                CurrentUser = new User();
                currentUserBindingSource.DataSource = CurrentUser;
                Text = @"New User";
            }
            accountsbindingSource.DataSource = Accounts;
            storebindingSource.DataSource = Stores;
            groupsbindingSource.DataSource = Groups;
        }
 public static bool CreateUser(User user)
 {
     try
     {
         Repository.Users.Add(user);
         return true;
     }
     catch(Exception exception)
     {
         errorLogger.SaveError(0,0,0,2,"Create User","",exception);
         return false;
     }
 }