예제 #1
0
        public ActionResult EditCompanyAdmin(string id,RegistrationModel rm)
        {
            if (Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin"))
            {

                if (ModelState.IsValid)
                {
                    try
                    {
                        var selectedAdmin = inBidDB.aspnet_Users.Where(x => x.UserName == id).First();
                        var company = inBidDB.Companies.Where(x => x.CompanyId == selectedAdmin.CompanyId).First();
                        var adress = inBidDB.Adresses.Where(x => x.AdressId == company.AdressId).First();
                        var membershipData = inBidDB.aspnet_Membership.Where(x => x.UserId == selectedAdmin.UserId).First();

                        selectedAdmin.UserName = rm.UserName;
                        selectedAdmin.FirstName = rm.FirstName;
                        selectedAdmin.LastName = rm.LastName;
                        selectedAdmin.Phone = rm.Phone;
                        selectedAdmin.LanguageId = rm.LanguageId;

                        membershipData.Email = rm.Email;

                        company.Name = rm.Name;
                        company.BidderQuality = rm.BidderQuality;
                        company.BidderViewQuality = rm.BidderViewQuality;
                        company.AuctionQuality = rm.AuctionQuality;
                        company.DateEditAuctionQuality = DateTime.UtcNow;


                        adress.Adress1 = rm.Adress;
                        adress.City = rm.City;
                        adress.Region = rm.Region;
                        adress.PostalCode = rm.PostalCode;
                        adress.CountryId = rm.CountryId;

                        inBidDB.SaveChanges();


                        TempData["Message"] = string.Format("Dane firmy {0} zostały zmienione", company.Name);
                        return RedirectToAction("CompanyAdmins", "Account");
                    }
                    catch
                    {
                        ModelState.AddModelError("", "");
                        PopulateLanguagesDropDownList(rm.LanguageId);
                        PopulateCountiresDropDownLists(rm.CountryId);
                        return View(rm);
                    }
                }
             
            }
            
                return View("AccessDenied");
        }
예제 #2
0
        public ActionResult RegisterAdmin(RegistrationModel model)
        {
            if (Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin"))
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        // Attempt to register the user
                        MembershipCreateStatus createStatus;


                        Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, false, null, out createStatus);




                        int adresId = 0;
                        int companyId = 0;
                        object _lock = 0;

                        lock (_lock)
                        {
                            Adress a = new Adress
                            {
                                Adress1 = model.Adress,
                                City = model.City,
                                PostalCode = model.PostalCode,
                                Region = model.Region,
                                CountryId = model.CountryId
                            };

                            inBidDB.AddToAdresses(a);
                            inBidDB.SaveChanges();

                            adresId = (from adr in inBidDB.Adresses select adr).OrderByDescending(x => x.AdressId).First().AdressId;


                            Company c = new Company
                            {
                                Name = model.Name,
                                AdressId = adresId,
                                 BidderQuality=model.BidderQuality,
                                  BidderViewQuality=model.BidderViewQuality,                                   
                                     AuctionQuality=model.AuctionQuality,
                                      DateEditAuctionQuality=DateTime.UtcNow
                                   //   DateEndAuctionQuality=DateTime.UtcNow+TimeSpan.FromDays(30)
                                
                            };

                            inBidDB.AddToCompanies(c);
                            inBidDB.SaveChanges();
                            //to trzeba przerobić
                            companyId = (from adr in inBidDB.Companies select adr).OrderByDescending(x => x.CompanyId).First().CompanyId;
                         //   model.CompanyId = companyId;
                        }

                        // var adresId = (from adr in inBidDB.Adresses select adr).OrderByDescending(x => x.AdressId).First().AdressId;

                        //InsertedRow.AdressId = adresId;
                        var InsertedRow = inBidDB.aspnet_Users.Where(x => x.UserName == model.UserName).First();
                        InsertedRow.FirstName = model.FirstName;
                        InsertedRow.LastName = model.LastName;
                        InsertedRow.LanguageId = model.LanguageId;
                        InsertedRow.CompanyId = companyId;

                       // InsertedRow.CompanyId = companyId;

                        InsertedRow.Phone = model.Phone;


                        inBidDB.SaveChanges();


                        if (createStatus == MembershipCreateStatus.Success)
                        {
                            setLanguage(model.UserName);
                            //FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                            // FormsAuth.SignIn(model.UserName, false /* createPersistentCookie */);
                            Roles.AddUserToRole(model.UserName, "Admin");

                            string path = urlApp + "/Account/ActiveUser?userId=" + InsertedRow.UserId;
                            //string path = Url.Action("ActiveCompanyAdmin", "Account", new { userId = InsertedRow.UserId }, Request.Url.Scheme);
                            MailHelper.SendRegistrationAdminMail(model.Email, model.UserName, model.Password, InsertedRow.UserId, model.Name, path);


                            //if (Request.IsAjaxRequest())
                            //{
                            //    // Same idea as above
                            //    return PartialView("_AdminRegistrationCompleted", model);
                            //}

                            TempData["Message"] = string.Format("Administrator " + model.UserName + " firmy " + model.Name + " zostal zarejestrowany.");
                            return RedirectToAction("CompanyAdmins");
                        }
                        else
                        {
                            ModelState.AddModelError("", ErrorCodeToString(createStatus));
                        }
                    }
                }
                catch (DataException e)
                {
                    ModelState.AddModelError("", "");
                }

                PopulateLanguagesDropDownList(model.LanguageId);
                PopulateCountiresDropDownLists(model.CountryId);
                // If we got this far, something failed, redisplay form
                return View(model);
            }

            if (Request.IsAjaxRequest())
            {
                return PartialView("_AccessDenied");

            }
            //return PartialView();
            return View("AccessDenied");
        }
예제 #3
0
        public ActionResult EditCompanyAdmin(string id)
        {
            if (Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin"))
            {
                var selectedAdmin = inBidDB.aspnet_Users.Where(x => x.UserName == id).First();
                var company=inBidDB.Companies.Where(x=>x.CompanyId==selectedAdmin.CompanyId).First();
                var adress=inBidDB.Adresses.Where(x=>x.AdressId==company.AdressId).First();
                var membershipData=inBidDB.aspnet_Membership.Where(x=>x.UserId==selectedAdmin.UserId).First();


                PopulateLanguagesDropDownList(selectedAdmin.LanguageId);
                PopulateCountiresDropDownLists(adress.CountryId);
                

                RegistrationModel rm = new RegistrationModel
                {
                    
                UserName=selectedAdmin.UserName,
                FirstName=selectedAdmin.FirstName,
                LastName=selectedAdmin.LastName,
                 Phone=selectedAdmin.Phone,
               //  CompanyId=selectedAdmin.CompanyId,
                 LanguageId=selectedAdmin.LanguageId,
                 Email=membershipData.Email,
                 Password=membershipData.Password,
                 ConfirmPassword=membershipData.Password,
                 Name=company.Name,
                 Adress=adress.Adress1,
                 City=adress.City,
                 Region=adress.Region,
                 PostalCode=adress.PostalCode,
                  CountryId=adress.AdressId,
                   AuctionQuality=(byte)company.AuctionQuality,
                   BidderQuality=(byte)company.BidderQuality,
                   BidderViewQuality=(byte)company.BidderViewQuality       



                };

                return View(rm);
            }
            return View("AccessDenied");
        }
예제 #4
0
        public ActionResult RegisterAdmin()
        {
            if (Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin"))
            {
                PopulateLanguagesDropDownList();
                PopulateCountiresDropDownLists();


                RegistrationModel rm = new RegistrationModel
                {
                    AuctionQuality = 10,
                    BidderQuality = 1,
                    BidderViewQuality = 1


                };

                //if (Request.IsAjaxRequest())
                //{
                //    return PartialView("_RegisterAdmin");

                //}

                return View(rm);
            }
            if (Request.IsAjaxRequest())
            {
                return PartialView("_AccessDenied");

            }
            //return PartialView();
            return View("AccessDenied");
        }