public ActionResult ChangeProfile(UpdateProfileViewModel model, HttpPostedFileBase avatar)
        {
            var user = db.Accounts.Where(m => m.Username == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                user.Name = model.Name;
                user.DOB  = model.DOB;
                user.Tel  = model.Tel;

                //change avatar in profile
                if (avatar != null)
                {
                    var img     = Path.GetFileName(avatar.FileName);
                    var pathImg = Path.Combine(Server.MapPath("~/Files/Avatar/"), img);
                    avatar.SaveAs(pathImg);
                    user.Avatar = img;
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(Redirect("Profile"));
            }
            user.Avatar = model.Avatar;
            user.Name   = model.Name;
            return(View("ChangeProfile", model));
        }
Пример #2
0
        public ActionResult MagazineCreateOrEdit(Magazine magazine, HttpPostedFileBase PDFfile, HttpPostedFileBase ImgFile)
        {
            ViewBag.list = AcaYearList();
            if (ModelState.IsValid)
            {
                Magazine obj = new Magazine();

                obj.Id             = magazine.Id;
                obj.Name           = magazine.Name;
                obj.OpenDate       = magazine.OpenDate;
                obj.CloseDate      = magazine.CloseDate;
                obj.AcademicYearID = magazine.AcademicYearID;
                obj.Description    = magazine.Description;

                if (magazine.Id == 0)
                {
                    obj.Status = true;
                    db.Magazines.Add(obj);
                    db.SaveChanges();
                }
                else
                {
                    //upload file
                    if (PDFfile != null)
                    {
                        string pdf     = Path.GetFileName(PDFfile.FileName);
                        string pdfPath = Path.Combine(Server.MapPath("~/Files/Doc/"), pdf);
                        PDFfile.SaveAs(pdfPath);

                        obj.PDFfile = pdf;
                    }
                    if (ImgFile != null)
                    {
                        string img     = Path.GetFileName(ImgFile.FileName);
                        string imgPath = Path.Combine(Server.MapPath("~/Files/Image/"), img);
                        ImgFile.SaveAs(imgPath);

                        obj.ImgFile = img;
                    }
                    obj.Status          = magazine.Status;
                    db.Entry(obj).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(Redirect("Magazine"));
            }

            if (magazine.Id == 0)
            {
                return(View("MagazineCreate", magazine));
            }
            return(View("MagazineEdit", magazine));
        }
Пример #3
0
        public ActionResult CoordinatorComment(CommentViewModel model)
        {
            if (ModelState.IsValid)
            {
                Comment obj = new Comment();
                obj.Message        = model.Message;
                obj.AccountId      = model.AccountId;
                obj.ContributionId = model.ContributionId;
                obj.SubmitDate     = DateTime.Now.ToString();

                db.Comments.Add(obj);
                db.SaveChanges();

                return(RedirectToAction("ContributionDetail", new { contriId = model.ContributionId, numb = model.Number }));
            }
            return(View());
        }
Пример #4
0
        public ActionResult AccountCreate(Account account)
        {
            ViewBag.Roles = RoleList();
            if (ModelState.IsValid)
            {
                Account accObj = new Account();

                accObj.Id = account.Id;

                accObj.RoleId   = account.RoleId;
                accObj.Username = account.Username;
                accObj.Password = account.Password;
                accObj.Name     = account.Name;
                accObj.DOB      = account.DOB;
                accObj.Tel      = account.Tel;
                accObj.Email    = account.Email;

                ////upload avatar for account
                //string img = Path.GetFileName(avatar.FileName);
                //string pathImg = Path.Combine(Server.MapPath("~/Files/Avatar/"), img);
                //avatar.SaveAs(pathImg);
                //accObj.Avatar = img;

                var usernameExist = db.Accounts.Where(m => m.Username == account.Username).Any();
                var emailExist    = db.Accounts.Where(m => m.Email == account.Email).Any();
                if (!usernameExist && !emailExist)
                {
                    db.Accounts.Add(accObj);
                    db.SaveChanges();
                }
                else if (emailExist)
                {
                    ViewBag.emailErr = String.Format("This Email is already exist!");
                    return(View());
                }
                else if (usernameExist)
                {
                    ViewBag.usernameErr = String.Format("This Username is already exist!");
                    return(View());
                }
                return(Redirect("Account"));
            }

            return(View(account));
        }
        public ActionResult ContributionSubmitFile(Contri_FileViewModel model, HttpPostedFileBase fileDoc, HttpPostedFileBase fileImage)
        {
            if (ModelState.IsValid)
            {
                //Contribution database
                Contribution objContri     = new Contribution();
                var          userLogged    = db.Accounts.Where(m => m.Username == User.Identity.Name).FirstOrDefault();
                var          acc_facLogged = db.Accounts_Faculties.Where(m => m.Account.Username == User.Identity.Name).FirstOrDefault();
                var          magazineId    = db.Magazines.Where(x => x.Status == true).FirstOrDefault();
                var          maga_facList  = db.Magazines_Faculties.Where(m => m.MagazineId == magazineId.Id).ToList();

                objContri.AccountId  = userLogged.Id;
                objContri.SubmitDate = DateTime.Now;
                objContri.Status     = null;
                foreach (var item in maga_facList)
                {
                    if (item.FacultyId == acc_facLogged.FacultyId)
                    {
                        objContri.FacultyId = item.FacultyId;
                    }
                }
                objContri.MagazineId = magazineId.Id;

                db.Contributions.Add(objContri);
                db.SaveChanges();

                int contriId = objContri.Id;
                //File Database
                Models.File obj   = new Models.File();
                string      doc   = null;
                string      image = null;
                if (fileImage != null)
                {
                    image = System.IO.Path.GetFileName(fileImage.FileName);
                    string imagePath = System.IO.Path.Combine(Server.MapPath("~/Files/Image/"), image);
                    fileImage.SaveAs(imagePath);
                    obj.FileName = fileImage != null ? image : obj.FileName;
                }
                if (fileDoc != null)
                {
                    doc = System.IO.Path.GetFileName(fileDoc.FileName);
                    string docPath = System.IO.Path.Combine(Server.MapPath("~/Files/Doc/"), doc);

                    fileDoc.SaveAs(docPath);

                    obj.ContributionId = contriId;
                    obj.Name           = model.Name;
                    obj.FileType       = fileDoc != null ? doc : obj.FileType;
                    obj.Description    = model.Description;

                    db.Files.Add(obj);
                    db.SaveChanges();

                    var user    = db.Accounts.Where(m => m.Username == User.Identity.Name).FirstOrDefault();
                    var acc_fac = db.Accounts_Faculties.ToList();

                    var           Coor     = db.Accounts.Where(m => m.Role.Name == "Coordinator").ToList();
                    var           facId    = 0;
                    List <string> coorList = new List <string>();
                    foreach (var item in acc_fac)
                    {
                        if (item.AccountId == user.Id)
                        {
                            facId = item.FacultyId;
                        }
                    }

                    foreach (var item in Coor)
                    {
                        foreach (var item2 in item.Account_Faculties)
                        {
                            if (item2.FacultyId == facId)
                            {
                                coorList.Add(item2.Account.Email);
                            }
                        }
                    }
                    //string x =
                    //var rand = new Random();
                    //int x = rand.
                    //string gmail = rand.Next(coorList.)

                    string body = string.Empty;
                    using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailForm/SendMailWithNewContriBution.html")))
                    {
                        body = reader.ReadToEnd();
                    }
                    body = body.Replace("{Student}", user.Email);
                    foreach (var item in coorList)
                    {
                        body = body.Replace("{Coordinator}", item);
                        bool IsSendEmail = SendEmail.GmailSend(item, "Notification", body, true);
                    }
                }

                return(RedirectToAction("Contribution", "Student"));
            }
            return(View(model));
        }