/// <summary>
        /// Saves the branch user.
        /// </summary>
        /// <param name="branchUserView">The branch user view.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">branchUserView</exception>
        public string SaveBranchUser(IBranchListView branchUserView)
        {
            var result = string.Empty;

            if (branchUserView == null)
            {
                throw new ArgumentNullException(nameof(branchUserView));
            }

            var view = new UserBranch
            {
                BranchId           = branchUserView.BranchId,
                IsActive           = true,
                UserRegistrationId = branchUserView.UserId
            };

            try
            {
                using (
                    var dbContext = (PitalyticsEntities)this.dbContextFactory.GetDbContext())
                {
                    dbContext.UserBranches.Add(view);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("SaveUserBranch - {0} , {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// populates a UserBranch with its child entities
 /// </summary>
 /// <param name="userBranch"></param>
 /// <param name="fillChilds"></param>
 private void FillUserBranchWithChilds(UserBranch userBranchObject, bool fillChilds)
 {
     // populate child data for a userBranchObject
     if (userBranchObject != null)
     {
     }
 }
        /// <summary>
        /// Retrieves list of UserBranch objects from SqlCommand, after database query
        /// number of rows retrieved and returned depends upon the rows field value
        /// </summary>
        /// <param name="cmd">The command object to use for query</param>
        /// <param name="rows">Number of rows to process</param>
        /// <returns>A list of UserBranch objects</returns>
        private UserBranchList GetList(SqlCommand cmd, long rows)
        {
            // Select multiple records
            SqlDataReader reader;
            long          result = SelectRecords(cmd, out reader);

            //UserBranch list
            UserBranchList list = new UserBranchList();

            using ( reader )
            {
                // Read rows until end of result or number of rows specified is reached
                while (reader.Read() && rows-- != 0)
                {
                    UserBranch userBranchObject = new UserBranch();
                    FillObject(userBranchObject, reader);

                    list.Add(userBranchObject);
                }

                // Close the reader in order to receive output parameters
                // Output parameters are not available until reader is closed.
                reader.Close();
            }

            return(list);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("BranchId,BranchName")] UserBranch userBranch)
        {
            if (id != userBranch.BranchId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userBranch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserBranchExists(userBranch.BranchId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView("~/Areas/AppIdentity/Views/UserBranch/CreateEdit.cshtml", userBranch));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update UserBranch Object.
        /// Data manipulation processing for: new, deleted, updated UserBranch
        /// </summary>
        /// <param name="userBranchObject"></param>
        /// <returns></returns>
        public bool Update(UserBranch userBranchObject)
        {
            bool success = false;

            success = UpdateBase(userBranchObject);

            return(success);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("BranchId,BranchName")] UserBranch userBranch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userBranch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView("~/Areas/AppIdentity/Views/UserBranch/CreateEdit.cshtml", userBranch));
        }
Ejemplo n.º 7
0
        public ActionResult SaveUserBranch(int UserID, List <Branch> Check)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    RBACUser rUser = new RBACUser(Session["UserName"].ToString());
                    if (!rUser.HasPermission("UserBranch_Insert"))
                    {
                        return(Json("X", JsonRequestBehavior.AllowGet));
                    }
                    var IsExistBr = _userbranchService.All().Where(x => x.Userid == UserID.ToString()).ToList();
                    foreach (var data in IsExistBr)
                    {
                        _userbranchService.Delete(data);
                        _userbranchService.Save();
                    }
                    if (Check != null)
                    {
                        foreach (var data in Check)
                        {
                            if (Check.Count != 0)
                            {
                                List <UserBranch> userbranchList = new List <UserBranch>();

                                UserBranch userBranchAdd = new UserBranch();
                                userBranchAdd.BranchCode = data.BranchCode;
                                userBranchAdd.Userid     = UserID.ToString();

                                userbranchList.Add(userBranchAdd);

                                _userbranchService.Add(userBranchAdd);
                                _userbranchService.Save();
                            }

                            //else
                            //{
                            //
                            //}
                        }
                        // transaction.Dispose();
                        // return Json("3", JsonRequestBehavior.AllowGet);
                    }
                    transaction.Complete();
                    //Check.Clear();
                    return(Json("1", JsonRequestBehavior.AllowGet));
                }
                catch (Exception)
                {
                    transaction.Dispose();
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }
Ejemplo n.º 8
0
        public UserBranch MapEFToModel(EF.Models.UserBranch data)
        {
            var userBranch = new UserBranch()
            {
                BranchId   = data.BranchId,
                UserId     = data.UserId,
                BranchName = data.Branch != null ? data.Branch.Name : "",
            };

            return(userBranch);
        }
Ejemplo n.º 9
0
        public void SaveUserBranch(UserBranchDTO userBranchDTO)
        {
            var userBranch = new UserBranch()
            {
                BranchId  = userBranchDTO.BranchId,
                UserId    = userBranchDTO.UserId,
                TimeStamp = DateTime.Now,
            };

            this.UnitOfWork.Get <UserBranch>().AddNew(userBranch);
            this.UnitOfWork.SaveChanges();
        }
Ejemplo n.º 10
0
        public AdminController()
        {
            //Object Initialisation
            _parcelService   = new ABCParcelService();
            _abcLib          = new ABCLibrary();
            _DBcontext       = new ABC.Models.ApplicationDbContext();
            _userBranch      = new UserBranch();
            _branchRecording = new Branch();

            this.ApplicationDbContext = new ApplicationDbContext();
            this.UserManager          = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(this.ApplicationDbContext));
        }
Ejemplo n.º 11
0
 public ActionResult ManageUserBranch(UserBranch New_UserBranch_Record)
 {
     try
     {
         _parcelService.CreateUserBranch(New_UserBranch_Record);
         return(RedirectToAction("../Home/DisplayParcels"));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult SaveSecUserInfo(SecUserInfo SecUsrInfo)
        {
            RBACUser rUser = new RBACUser(Session["UserName"].ToString());

            if (!rUser.HasPermission("SecUserInfo_Insert"))
            {
                return(Json("X", JsonRequestBehavior.AllowGet));
            }

            string eCode = "";

            using (var transaction = new TransactionScope())
            {
                try
                {
                    var UserInfo = _secUserInfoService.All().ToList().FirstOrDefault(x => x.UserName == SecUsrInfo.UserName);

                    if (UserInfo == null)
                    {
                        SecUserInfo SecUinf = new SecUserInfo();
                        SecUinf.UserName   = SecUsrInfo.UserName;
                        SecUinf.Password   = SHA1.Encode(SecUsrInfo.Password);
                        SecUinf.Email      = SecUsrInfo.Email;
                        SecUinf.CreateDate = System.DateTime.Now;
                        _secUserInfoService.Add(SecUinf);
                        _secUserInfoService.Save();
                        //For user branch table by Farhad
                        var        userId = _secUserInfoService.All().ToList().Where(x => x.UserName == SecUsrInfo.UserName).Select(s => s.UserID).FirstOrDefault();
                        UserBranch UB     = new UserBranch();
                        UB.Userid     = userId.ToString();
                        UB.BranchCode = "01";
                        _userBranchService.Add(UB);
                        _userBranchService.Save();
                        eCode = "1";
                    }
                    else
                    {
                        eCode = "2";
                    }

                    transaction.Complete();

                    return(Json(eCode, JsonRequestBehavior.AllowGet));
                }
                catch (Exception)
                {
                    transaction.Dispose();
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }
Ejemplo n.º 13
0
        public UserBranch GetBranchManager(string branchManagerId)
        {
            var result = _dataService.GetUserBranch(branchManagerId);

            if (result == null)
            {
                UserBranch userBranch = null;
                return(userBranch);
            }
            else
            {
                return(MapEFToModel(result));
            }
        }
        /// <summary>
        /// Retrieves UserBranch object from SqlCommand, after database query
        /// </summary>
        /// <param name="cmd">The command object to use for query</param>
        /// <returns>UserBranch object</returns>
        private UserBranch GetObject(SqlCommand cmd)
        {
            SqlDataReader reader;
            long          rows = SelectRecords(cmd, out reader);

            using (reader)
            {
                if (reader.Read())
                {
                    UserBranch userBranchObject = new UserBranch();
                    FillObject(userBranchObject, reader);
                    return(userBranchObject);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Update base of UserBranch Object.
        /// Data manipulation processing for: new, deleted, updated UserBranch
        /// </summary>
        /// <param name="userBranchObject"></param>
        /// <returns></returns>
        public bool UpdateBase(UserBranch userBranchObject)
        {
            // use of switch for different types of DML
            switch (userBranchObject.RowState)
            {
            // insert new rows
            case BaseBusinessEntity.RowStateEnum.NewRow:
                return(Insert(userBranchObject));

            // delete rows
            case BaseBusinessEntity.RowStateEnum.DeletedRow:
                return(Delete(userBranchObject.Id));
            }
            // update rows
            using (UserBranchDataAccess data = new UserBranchDataAccess(ClientContext))
            {
                return(data.Update(userBranchObject) > 0);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Insert new userBranch.
 /// data manipulation for insertion of UserBranch
 /// </summary>
 /// <param name="userBranchObject"></param>
 /// <returns></returns>
 private bool Insert(UserBranch userBranchObject)
 {
     // new userBranch
     using (UserBranchDataAccess data = new UserBranchDataAccess(ClientContext))
     {
         // insert to userBranchObject
         Int32 _Id = data.Insert(userBranchObject);
         // if successful, process
         if (_Id > 0)
         {
             userBranchObject.Id = _Id;
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 17
0
        public ActionResult LogParcelMovement(Parcel_Tracking_Log Log_Record)
        {
            var _loginUser = UserManager.FindById(User.Identity.GetUserId());

            _userBranch            = _parcelService.GetUserBranchCode(_loginUser.UserName);
            Log_Record.branch_code = _userBranch.branch_code;
            _branchRecording       = _parcelService.GetBranch(Log_Record.branch_code);
            Log_Record.date        = DateTime.Now;
            Log_Record.location    = _branchRecording.city;

            try
            {
                _parcelService.LogParcelMovement(Log_Record);
                //return RedirectToAction("DisplayParcels", "Home");
                return(View());
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 18
0
 //To Implement
 //Method name: CreateUserBranch
 //Return Type: Void
 //Parameter type: Branch
 //Parsmenter Name: New_UserBranch_Record
 //Submission: Assignment 3
 //Date: 21-04-2015
 public void CreateUserBranch(UserBranch New_UserBranch_Record)
 {
     _parcelDAO.CreateUserBranch(New_UserBranch_Record);
 }
Ejemplo n.º 19
0
 public void Add(UserBranch obj)
 {
     _service.Add(obj);
 }
Ejemplo n.º 20
0
 public void Delete(UserBranch obj)
 {
     _service.Delete(obj);
 }
Ejemplo n.º 21
0
 public void Update(UserBranch obj)
 {
     _service.Update(obj);
 }
Ejemplo n.º 22
0
 //To Implement
 //Method name: CreateUserBranch
 //Return Type: Void
 //Parameter type: Branch
 //Parsmenter Name: New_UserBranch_Record
 //Submission: Assignment 3
 //Date: 21-04-2015
 public void CreateUserBranch(UserBranch New_UserBranch_Record)
 {
     _dbcontext.UserBranch.Add(New_UserBranch_Record);
     _dbcontext.SaveChanges();
 }
Ejemplo n.º 23
0
 public void Save(UserBranch model)
 {
     _userService.SaveUserBranch(model.UserId, model.BranchId);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Fill External Childs of UserBranch Object.
 /// </summary>
 /// <param name="userBranchObject"></param>
 /// <returns></returns>
 public void FillChilds(UserBranch userBranchObject)
 {
     ///Fill external information of Childs of UserBranchObject
 }
Ejemplo n.º 25
0
 public void Setvalues(UserBranch entity, UserBranch existingEntity)
 {
     _service.Setvalues(entity, existingEntity);
 }
Ejemplo n.º 26
0
        public ActionResult Register(Employee model, string[] EmployeesCustom, string[] roles, string returnUrl)
        {
            var isExist = _employeeService.All().FirstOrDefault(x => x.Email == model.Email.ToLower());

            if (isExist == null)
            {
                try
                {
                    model.UserName = model.Email;
                    ModelState.Clear();
                    UpdateModel(model);
                }
                catch
                {
                }
                if (ModelState.IsValid)
                {
                    if (model.Password == model.ConfirmPassword)
                    {
                        try
                        {
                            Employee employee = new Employee();
                            employee.UserName = model.UserName;
                            employee.Email    = model.Email;
                            //employee.BranchCode = model.BranchCode;
                            employee.IsActive = false;

                            WebSecurity.CreateUserAndAccount(model.Email.ToLower(), model.Password);
                            Roles.AddUserToRoles(employee.Email, roles);

                            _employeeService.Add(employee);
                            _employeeService.Save();

                            int id = employee.Id;//_employeeService.All().LastOrDefault().Id;

                            List <string> userbranch = EmployeesCustom.ToList();



                            string UID = Convert.ToString(id);
                            //List<UserBranch> userList = new List<UserBranch>();
                            foreach (var BranchCode in userbranch)
                            {
                                UserBranch userbranchs = new UserBranch();
                                userbranchs.Userid     = UID;
                                userbranchs.BranchCode = BranchCode;
                                //userList.Add(userbranchs);
                                _userbranchService.Add(userbranchs);
                                _userbranchService.Save();
                            }

                            // model.Branchs = userList;
                            //_employeeService.Add(model);

                            // _userbranchService.SaveChanges();

                            //Roles.AddUserToRole(model.Email, "");
                            ViewBag.Roles = roles;

                            ViewBag.BranchCode = new SelectList(_branchService.All().ToList(), "BranchCode", "BranchName");
                            ViewBag.Id         = new SelectList(_employeeService.All().ToList(), "Id", "UserName");

                            return(RedirectToAction("Register"));
                        }
                        catch (MembershipCreateUserException e)
                        {
                            ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("error", "Password doesn't match. Please recheck password");
                    }
                }
            }
            else
            {
                ViewBag.IsAlreadyRegistered = "This User Name is already registered.";
            }
            List <string> allRole = new List <string>();

            foreach (string role in System.Web.Security.Roles.GetAllRoles().ToList())
            {
                allRole.Add(role);
            }
            ViewBag.Roles      = allRole;
            ViewBag.BranchCode = new SelectList(_branchService.All().ToList(), "BranchCode", "BranchName");
            ViewBag.Id         = new SelectList(_employeeService.All().ToList(), "Id", "UserName");
            return(View(model));
        }