Ejemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Companies EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCompanies(Company company)
 {
     base.AddObject("Companies", company);
 }
Ejemplo n.º 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");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new Company object.
 /// </summary>
 /// <param name="companyId">Initial value of the CompanyId property.</param>
 public static Company CreateCompany(global::System.Int32 companyId)
 {
     Company company = new Company();
     company.CompanyId = companyId;
     return company;
 }