Exemplo n.º 1
0
 public virtual ActionResult Delete(int id)
 {
     try
     {
         var model = _univercityStructureService.Where(d => d.ParentId == id || (d.Id == id && d.ParentId == null)).FirstOrDefault();
         if (model != null)
         {
             return(Json(new { isError = true, Msg = "این گروه آموزشی دارای زیر شاخه می باشد!" }));
         }
         model = _univercityStructureService.Where(s => s.Id == id).Include(i => i.Requests).FirstOrDefault();
         if (model == null)
         {
             return(Json(new { isError = true, Msg = "رکورد مورد نظر یافت نشد!" }));
         }
         if (model.Requests.Count > 0)
         {
             return(Json(new { isError = true, Msg = "این گروه آموزشی دارای گردش می باشد!" }));
         }
         _univercityStructureService.Delete(id);
         Log log = new Log()
         {
             UserId          = int.Parse(User.Identity.GetUserId()),
             Operation       = Operations.ساختار_دانشگاه,
             OperationDetail = OperationsDetail.حذف,
             Description     = " حذف ساختار دانشگاه به شماره" + id
         };
         _logService.AddNewLog(log);
         _unitOfWork.SaveChanges();
         return(Json(new { isError = false, Msg = "حذف شد" }));
     }
     catch (Exception)
     {
         return(Json(new { isError = true, Msg = "حذف نشد" }));
     }
 }
Exemplo n.º 2
0
        public virtual ActionResult RenderComboRecievers(int enumvalue)
        {
            try
            {
                var roleName = ((Roles)enumvalue).ToString();
                int uid      = int.Parse(User.Identity.GetUserId());
                var role     = _roleManager.FindRoleByName(((Roles)enumvalue).ToString());
                if (role == null)
                {
                    new Exception();
                }
                var userRole = _roleManager.GetAllCustomUserRole().Include(u => u.Department).FirstOrDefault(r => r.RoleId == role.Id);
                if (userRole == null)
                {
                    new Exception();
                }
                switch (roleName)
                {
                case "MG":
                    var ListMG = _univercityStructureService.Where(u => u.Level == userRole.Department.Level).ToList();
                    ViewBag.Recievers = new SelectList(ListMG, "Id", "Name", 0);
                    break;

                case "RD":
                    var ListRD = _univercityStructureService.Where(u => u.Level == userRole.Department.Level);
                    ViewBag.Recievers =
                        new SelectList(ListRD, "Id", "Name", 0);
                    break;

                case "RK":
                    var userRK = from a in _userService.Where(u => u.Id == userRole.UserId).Include(p => p.Profile)
                                 select new { Name = a.Profile.Name + " " + a.Profile.Family, Id = a.Id };
                    ViewBag.Recievers = new SelectList(userRK, "Id", "Name", 0);
                    break;

                case "MA":
                    var userMA = from a in _userService.Where(u => u.Id == userRole.UserId).Include(p => p.Profile)
                                 select new { Name = a.Profile.Name + " " + a.Profile.Family, Id = a.Id };
                    ViewBag.Recievers = new SelectList(userMA, "Id", "Name", 0);
                    break;

                case "User":
                    var user = from a in _userService.GetAllUsersAsQueryable().Include(p => p.Profile)
                               select new { Name = a.Profile.Name + " " + a.Profile.Family, Id = a.Id };
                    ViewBag.Recievers = new SelectList(user, "Id", "Name", 0);
                    break;

                default:
                    var userDefault = from a in _userService.GetAllUsersAsQueryable().Include(p => p.Profile)
                                      select new { Name = a.Profile.Name + " " + a.Profile.Family, Id = a.Id };
                    ViewBag.Recievers = new SelectList(userDefault, "Id", "Name", 0);
                    break;
                }

                return(PartialView("_ComboRecievers"));
            }
            catch (Exception ex)
            {
                return(PartialView("_NotFound"));
            }
        }
Exemplo n.º 3
0
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    try
                    {
                        BaseUserLogin baseuserlogin = _userService.Where(x => x.CodeMeli == model.CodeMeli && x.CodeEstekhdam == model.CodeEstekhdam).FirstOrDefault();
                        if (baseuserlogin == null)
                        {
                            ModelState.AddModelError("", "اطلاعات پایه کاربری وجود ندارد");
                            return(View(model));
                        }
                        if (baseuserlogin.Active)
                        {
                            ModelState.AddModelError("", "شماره شناسایی قبلا استفاده شده است");
                            return(View(model));
                        }
                        //throw new Exception("اطلاعات پایه کاربری وجود ندارد");
                        var user = new AppUser
                        {
                            UserName        = model.Email,
                            Email           = model.Email,
                            BaseUserLoginId = baseuserlogin.BaseUserLoginId
                        };
                        var result = await _userManager.CreateAsync(user, model.Password);

                        if (result.Succeeded)
                        {
                            baseuserlogin.Active = true;
                            _baseuserService.Edit(baseuserlogin);
                            var roleid    = _roleManager.FindRoleByName(Roles.User.ToString()).Id;
                            var departman = _univercity.Where(x => x.Level == 1).SingleOrDefault();
                            if (departman != null)
                            {
                                _roleManager.AddUserRole(user.Id, roleid, departman.Id);
                            }
                            _uow.SaveChanges();
                            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id);

                            var callbackUrl = Url.Action(MVC.Account.ActionNames.ConfirmEmail, MVC.Account.Name, new { userId = user.Id, code }, Request.Url.Scheme);
                            ViewBag.Link = callbackUrl;
                            //_emailIdentityService.SendEmailWithPostal("Reg.Html", user.Email, "", "", "تائید حساب کاربری ", "تائید حساب کاربری ", "جهت فعال سازی حساب کاربری خود بر روی لینک زیر کلیک کنید: <a href=\"" + callbackUrl + "\">link</a>");
                            var     def   = _definitionService.GetAllDefinitionsAsQueryable().FirstOrDefault();
                            dynamic email = new Email("Reg.Html");
                            email.To      = user.Email;
                            email.Title   = "تائید حساب کاربری ";
                            email.Subject = (def == null ? "تائید حساب کاربری " : "تائید حساب کاربری " + def.UniversityName);
                            email.Body    = "جهت فعال سازی حساب کاربری خود بر روی لینک زیر کلیک کنید";
                            email.Link    = callbackUrl;
                            //if (!string.IsNullOrWhiteSpace(email.To.ToString()))
                            //    email.Send();
                            scope.Complete();
                            return(View("DisplayEmail"));
                        }
                        addErrors(result);
                    }
                    catch (Exception ex)
                    {
                        ErrorSignal.FromCurrentContext().Raise(ex);
                        ModelState.AddModelError("", "عملیات با مشکل مواجه شد! " + ex.Message);
                        return(View(model));
                    }
                    finally
                    {
                        //scope.Dispose();
                    }
                }
            }

            return(View(model));
        }