Exemplo n.º 1
0
        public async Task <ActionResult> Edit([Bind(Include = "S_Id,SchoolName,Address,ContactNo,AltContactNo,FaxNo,Email,Website,Logo,RegistrationNo,DiseNo,IndexNo,EstablishedYear,Class,SchoolType")] SchoolInfo schoolInfo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(schoolInfo).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.SchoolType = new SelectList(db.SchoolTypes, "Type", "Type", schoolInfo.SchoolType);
            return(View(schoolInfo));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "RoleId,RoleName,Description")] Role role)
        {
            if (ModelState.IsValid)
            {
                db.Entry(role).State = EntityState.Modified;
                await db.SaveChangesAsync();

                System.Web.HttpContext.Current.Session["NOT"] = "You have successfully updated the Role";

                return(RedirectToAction("Index"));
            }
            return(View(role));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Edit([Bind(Include = "ModulesID,ModulesName,RoleID,glyphicon,ControllerName,ViewName,Name,IsWebForm,webFormUrl,MenuRank")] Module modules)
        {
            var    name     = db.Users.ToList().Where(a => a.Email == WebSecurity.CurrentUserName);
            string username = "";

            foreach (var p in name)
            {
                username = p.Username;
            }
            if (ModelState.IsValid)
            {
                db.Entry(modules).State = EntityState.Modified;
                await db.SaveChangesAsync(username);

                System.Web.HttpContext.Current.Session["NOT"] = "You have successfully updated the Module";

                return(RedirectToAction("Index"));
            }
            ViewBag.RoleID = new SelectList(db.Roles, "RoleId", "RoleName", modules.RoleID);
            var list4 = db.glyphicons.ToList();
            // Create List of SelectListItem
            List <SelectListItem> selectlist4 = new List <SelectListItem>();

            selectlist4.Add(new SelectListItem()
            {
                Text = "", Value = ""
            });
            foreach (var row in list4)
            {
                // Adding every record to list
                selectlist4.Add(new SelectListItem {
                    Text = row.glyphiconname, Value = row.glyphiconname.ToString()
                });
            }
            ViewBag.Dlyp = selectlist4;
            return(View(modules));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> ForgotPassword(LoginViewModel model, string returnUrl = "")
        {
            var p = Context.Users.Where(u => u.Email == model.Username).ToList().Take(1);

            // this
            if (p.Count() != 0)
            {
                foreach (var user in p)
                {
                    var mod = ModelState.First(c => c.Key == "Username");                                   // this
                    mod.Value.Errors.Add("Check your inbox an email has been sent with your new password"); // this
                                                                                                            // ViewBag.Message = "In database";

                    User userData = Context.Users.Where(u => u.UserId == user.UserId).SingleOrDefault();
                    //Update the Database
                    //Autogenerate password
                    string allowedChars = "";
                    allowedChars  = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
                    allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
                    allowedChars += "1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?";
                    char[]   sep            = { ',' };
                    string[] arr            = allowedChars.Split(sep);
                    string   passwordString = "";
                    string   password       = "";
                    string   temp           = "";
                    Random   rand           = new Random();
                    for (int i = 0; i < 14; i++)
                    {
                        temp            = arr[rand.Next(0, arr.Length)];
                        passwordString += temp;
                    }
                    password = passwordString;
                    string hPassword = ComputeHash(password, new SHA256CryptoServiceProvider());

                    userData.Password        = hPassword;
                    userData.ConfirmPassword = hPassword;
                    if (userData.BrokerName == null)
                    {
                        userData.BrokerCode = "MORCO";
                        userData.BrokerName = "Dry Associates";
                    }
                    Context.Entry(userData).State = EntityState.Modified;
                    Context.SaveChanges();
                    //sending emails
                    //content supposition

                    string messageBody = "<html><body ><p stlyle='color:lightblue;align:justify'>Username :  "******"  Password:"******"<br/>Dry Associates<br/>" +
                                         "62 Quorn Avenue, Arundel, Harare<br/>" +
                                         "Tel: +263 4 301201/3, 301422, 301203 / Mob: +263 777 726 850 " +
                                         " <img src=cid:myImageID></p></body></ html > ";

                    //create Alrternative HTML view
                    AlternateView htmlView = AlternateView.CreateAlternateViewFromString(messageBody, null, "text/html");

                    //Add Image
                    LinkedResource theEmailImage = new LinkedResource(Server.MapPath("~/images/MORCObos.jpg"));
                    theEmailImage.ContentId = "myImageID";

                    //Add the Image to the Alternate view
                    htmlView.LinkedResources.Add(theEmailImage);

                    //Add view to the Email Message


                    //var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                    var message = new MailMessage();
                    message.To.Add(new MailAddress(user.Email));               // replace with valid value
                    message.From    = new MailAddress("*****@*****.**"); // replace with valid value
                    message.Subject = "MORCObos Broker Back Office Login Credentials";
                    //message.Body = string.Format(body, "Admin", "*****@*****.**", messageBody);
                    message.IsBodyHtml = true;
                    message.AlternateViews.Add(htmlView);
                    using (var smtp = new SmtpClient())
                    {
                        smtp.Host      = "smtp.gmail.com";
                        smtp.Port      = 587;
                        smtp.EnableSsl = true;
                        ServicePointManager.ServerCertificateValidationCallback =
                            delegate(object s, X509Certificate certificate,
                                     X509Chain chain, SslPolicyErrors sslPolicyErrors)
                        { return(true); };
                        smtp.Timeout               = 10000;
                        smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "escrow123456789");

                        await smtp.SendMailAsync(message);
                    }
                }
            }
            else
            {
                var mod = ModelState.First(c => c.Key == "Username");  // this
                mod.Value.Errors.Add("Email does not exist in our records");
            }



            return(View(model));
        }