Esempio n. 1
0
        public ActionResult Create([Bind(Include = "Supervisors,Lecturers")] AllocatedLecturers allocatedLecturers)
        {
            var vari = allocatedLecturers.Supervisors;



            if (db.AllocatedLecturers.Any(ac => ac.Lecturers.Equals(allocatedLecturers.Lecturers)) && db.AllocatedLecturers.Any(acs => acs.Supervisors.Equals(allocatedLecturers.Supervisors)))

            {
                ModelState.AddModelError("Already exists", "Error");
                return(RedirectToAction("Edit", "Groups1"));
            }


            if (ModelState.IsValid)
            {
                db.AllocatedLecturers.Add(allocatedLecturers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Supervisor = new SelectList(db.AllocatedLecturers, "GroupID", "Supervisor", allocatedLecturers.Supervisors);
            ViewBag.Lecturers  = new SelectList(db.AllocatedLecturers, "Lecturers", "Lecturers", allocatedLecturers.Lecturers);


            return(View(allocatedLecturers));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "LecturerId,Name,Email,ContactNo,Module,Qualification,Avatar")] Lecturer lecturer, HttpPostedFileBase Avatar)
        {
            var extension = Path.GetExtension(Avatar.FileName);

            if (ModelState.IsValid && Avatar != null && (extension.Equals(".jpg") || extension.Equals(".jpeg") || extension.Equals(".GIF")))
            {
                string path = Server.MapPath("~/Content/Images2");
                //calling the image upload method in ValidateController
                lecturer.Avatar        = Validater.ImageUpload(Avatar, path);
                lecturer.Qualification = "Lecturer";
                lecturer.Module        = "Pending";
                //calling the RegisterSessionSet to set the sessions
                RegisterSessionSet(lecturer.Name, lecturer.Email, lecturer.Avatar, 0.0, lecturer.ContactNo, "Lecturer", lecturer.LecturerId);


                //Save Changes in DB
                db.Lecturers.Add(lecturer);

                RequestNew LecReq = new RequestNew {
                    Name = "Auro", Request = lecturer.Name + " Lecturer Been Added To the SEP Tool As a lectureCUT" + lecturer.Avatar + "CUT" + MvcApplication.time, Status = MvcApplication.Pr_two, Loaded = MvcApplication.Pr_two
                };
                db.RequestsNew.Add(LecReq);
                db.SaveChanges();


                return(RedirectToActionPermanent("Pending", "Register"));
            }
            else if (!(extension.Equals(".jpg") || extension.Equals(".jpeg") || extension.Equals(".GIF")))
            {
                TempData["error"] = "Please Use A Valid Avatar";
            }

            return(View(lecturer));
        }
        public ActionResult Create([Bind(Include = "ProjectId,ModuleId,Name,Description,Client,PreferedTechnologies")] Project project)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    ViewBag.ModuleName = db.Modules;
                    db.Projects.Add(project);
                    db.SaveChanges();

                    if (Session["UserName"] == null)
                    {
                        return(RedirectToAction("Login", "Register"));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                catch
                {
                    return(View(project));
                }
            }
            else
            {
                if ((string)Session["Position"] == "Lecturer")
                {
                    ViewBag.Client = (string)Session["UserName"];
                }
                ViewBag.ModuleName = db.Modules;
                return(View(project));
            }
        }
 public ActionResult Create([Bind(Include = "ModuleId,Description,MaxCount,Year,semester,LecturerIncharge,MaxLecPanel")] Module module)
 {
     if (db.Modules.Any(m => m.ModuleId.Equals(module.ModuleId))) //check modulecode already in the database table
     {
         TempData["ErrMsg1"] = "Module Code Already Exists!";
     }
     if (ModelState.IsValid)
     {
         try
         {
             db.Modules.Add(module);
             db.SaveChanges();
             TempData["Msg1"] = "Successfully Inserted";
             return(RedirectToAction("ViewAll"));
         }
         catch (Exception ex)
         {
             ComboValues();
             throw ex;
         }
     }
     else
     {
         ComboValues();
         return(View(module));
     }
 }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "ClientId,Company,Name,Email,ContactNo")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Create", "Projects", new { client = client.Name }));
            }

            return(View(client));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "RegistrationNo,Name,Email,ContactNo,CGPA,Avatar,CV")] Student student, HttpPostedFileBase Avatar, HttpPostedFileBase CV)
        {
            Session["UserName"] = student.Name;
            Session["Email"]    = student.Email;

            Session["CGPA"]      = student.CGPA;
            Session["CV"]        = student.CV;
            Session["ContactNo"] = student.ContactNo;
            Session["id"]        = student.RegistrationNo;
            Session["Position"]  = "student";
            if (ModelState.IsValid)
            {
                if (Avatar != null && Avatar.ContentLength > 0 && CV != null && CV.ContentLength > 0)
                {
                    var ex  = Path.GetExtension(Avatar.FileName);
                    var ex2 = Path.GetExtension(CV.FileName);
                    if (ex2.Equals(".PDF") || ex2.Equals(".pdf"))
                    {
                        var fileName = Path.GetFileName(CV.FileName);
                        var path     = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                        CV.SaveAs(path);
                        student.CV = path + "";
                    }
                    if (ex.Equals(".jpg") || ex.Equals(".jpeg") || ex.Equals(".GIF"))
                    {
                        var      fileName = Path.GetFileName(Avatar.FileName);
                        var      path     = Path.Combine(Server.MapPath("~/Content/Images2"), fileName);
                        string[] path2    = path.Split(new string[] { "SEP\\SEP" }, StringSplitOptions.None);
                        Avatar.SaveAs(path);
                        student.Avatar = path2[1] + "";
                    }
                }
                Session["Avatar"] = student.Avatar;
                db.Students.Add(student);
                db.SaveChanges();



                string        query2         = "insert into  dbo.Notification(Name,Notification,Status,Loaded) values(@a3,@a4,@a5,@a6)";
                List <object> parameterList2 = new List <object>();
                parameterList2.Add(new SqlParameter("@a3", "Auro"));
                parameterList2.Add(new SqlParameter("@a4", student.Name + " Student Been Added To the SEP Tool "));
                parameterList2.Add(new SqlParameter("@a5", 2));
                parameterList2.Add(new SqlParameter("@a6", 2));
                object[] parameters12 = parameterList2.ToArray();
                int      rs1          = db.Database.ExecuteSqlCommand(query2, parameters12);



                return(RedirectToActionPermanent("Index", "Home"));
            }

            return(View(student));
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "ProjectId,ModuleId,Name,Description,Client,PreferedTechnologies")] Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
Esempio n. 8
0
        public ActionResult Create([Bind(Include = "GroupID,ProjectID,Supervisor")] Group group)
        {
            if (ModelState.IsValid)
            {
                db.Groups.Add(group);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(group));
        }
Esempio n. 9
0
        public ActionResult Create([Bind(Include = "RegistrationNo,Name,Email,ContactNo,CGPA,Avatar,CV,Password")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
Esempio n. 10
0
        public ActionResult ViewLecIC([Bind(Include = "LecturerIncharge")] Module module)
        {
            if (ModelState.IsValid)
            {
                db.Entry(module).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("ViewAll"));
            }

            return(View(module));
        }
        public ActionResult Create([Bind(Include = "Id,Account,RoleId")] SUserRole sUserRole)
        {
            if (ModelState.IsValid)
            {
                db.SUserRoles.Add(sUserRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sUserRole));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "Id,Account,Name,Password")] SUser sUser)
        {
            if (ModelState.IsValid)
            {
                db.SUsers.Add(sUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sUser));
        }
        public ActionResult Publication(long Id, bool Enabled)
        {
            var promotion = DB2.Promotions.SingleOrDefault(x => x.Id == Id);

            if (promotion == null)
            {
                ErrorMessage("Акция не найдена");
                return(RedirectToAction("Index"));
            }
            ;
            if (!promotion.CheckSecurity(CurrentUser))
            {
                ErrorMessage("У вас нет прав для изменения данной акции");
                return(RedirectToAction("Index"));
            }

            promotion.Enabled = Enabled;

            DB2.PromotionHistory.Add(new PromotionSnapshot(CurrentUser, promotion, DB, DB2)
            {
                SnapshotName = "Изменения статуса акции"
            });
            DB2.SaveChanges();

            Mails.PromotionNotification(MailType.EditPromotion, promotion);
            var message = promotion.GetStatus().DisplayName();

            SuccessMessage($"Новый статус: {message}");
            return(RedirectToAction("Index", new { Id = Id.ToString() }));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            Group group = db.Groups.Find(id);

            db.Groups.Remove(group);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        /// <summary>
        /// Безвозвратно удалить
        /// </summary>
        /// <param name="id">идентификатор новости</param>
        /// <returns></returns>
        public ActionResult Delete(long id)
        {
            var news = DB2.Newses.Find(id);

            DB2.Newses.Remove(news);
            DB2.SaveChanges();

            Mails.NewsChanged(news, "Новость удалена", root);
            SuccessMessage("Новость удалена");
            return(RedirectToAction("Archive"));
        }
Esempio n. 16
0
        public ActionResult DeleteLinksToFile(int id, List <int> fileId)
        {
            var mailForm   = DB2.Emails.Find(id);
            var mediaFiles = DB2.MediaFiles.Where(x => fileId.Contains(x.Id)).ToList();

            foreach (var f in mediaFiles)
            {
                mailForm.MediaFiles.Remove(f);
            }
            DB2.SaveChanges();
            return(RedirectToAction("Edit", new { id }));
        }
Esempio n. 17
0
        public ActionResult Create([Bind(Include = "Supervisors,Lecturers")] AllocatedLecturers allocatedLecturers)
        {
            var vari = allocatedLecturers.Supervisors;

            int table_rows            = db.AllocatedLecturers.Count(ac => ac.Supervisors.Equals(allocatedLecturers.Supervisors));
            int MaxAllocatedLecturers = db.Modules.Max(ac => ac.MaxCount);

            if (MaxAllocatedLecturers <= table_rows)
            {
                TempData["max"] = "max";
                return(RedirectToAction("fuc", "Groups1"));
            }

            if (db.AllocatedLecturers.Any(ac => ac.Lecturers.Equals(allocatedLecturers.Lecturers)) &&
                db.AllocatedLecturers.Any(acs => acs.Supervisors.Equals(allocatedLecturers.Supervisors)))

            {
                TempData["exists"] = "exists";
                return(RedirectToAction("Edit", "Groups1"));
            }
            else if (ModelState.IsValid)
            {
                string        time          = DateTime.Now.ToString("HH:mm:ss tt");
                string        query         = "insert into  dbo.Requests(Name,Request,Status,Loaded) values(@a1,@a2,@a3,@a4)";
                List <object> parameterList = new List <object>();
                parameterList.Add(new SqlParameter("@a1", allocatedLecturers.Lecturers));
                parameterList.Add(new SqlParameter("@a2", Session["UserName"] + "Requests for a allocating on a Lecture panelCUT" + Session["Avatar"] + "CUT" + time + "CUT" + allocatedLecturers.id + "CUTAllocateLecturers"));
                parameterList.Add(new SqlParameter("@a3", 2));
                parameterList.Add(new SqlParameter("@a4", 2));
                object[] parameters123 = parameterList.ToArray();
                int      rs            = db.Database.ExecuteSqlCommand(query, parameters123);
                db.AllocatedLecturers.Add(allocatedLecturers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(allocatedLecturers));
            }
        }
Esempio n. 18
0
        public ActionResult Create([Bind(Include = "LecturerId,Name,Email,ContactNo,Module,Qualification,Avatar")] Lecturer lecturer, HttpPostedFileBase Avatar)
        {
            Session["UserName"]  = lecturer.Name;
            Session["Email"]     = lecturer.Email;
            Session["ContactNo"] = lecturer.ContactNo;
            Session["id"]        = lecturer.LecturerId;
            if (ModelState.IsValid)
            {
                if (Avatar != null)
                {
                    var ex = Path.GetExtension(Avatar.FileName);
                    if (ex.Equals(".jpg") || ex.Equals(".jpeg") || ex.Equals(".GIF"))
                    {
                        var      fileName = Path.GetFileName(Avatar.FileName);
                        var      path     = Path.Combine(Server.MapPath("~/Content/Images2"), fileName);
                        string[] path2    = path.Split(new string[] { "SEP\\SEP" }, StringSplitOptions.None);
                        Debug.Write(path2[1]);
                        Avatar.SaveAs(path);
                        lecturer.Avatar = path2[1] + "";
                    }
                }
                Session["Avatar"] = lecturer.Avatar;
                db.Lecturers.Add(lecturer);
                db.SaveChanges();
                string        query         = "insert into  dbo.Requests(Name,Request,Status,Loaded) values(@a1,@a2,@a3,@a4)";
                List <object> parameterList = new List <object>();
                parameterList.Add(new SqlParameter("@a1", "Auro"));
                parameterList.Add(new SqlParameter("@a2", lecturer.Name + "Been Added To the SEP Tool "));
                parameterList.Add(new SqlParameter("@a3", 2));
                parameterList.Add(new SqlParameter("@a4", 2));
                object[] parameters123 = parameterList.ToArray();
                int      rs            = db.Database.ExecuteSqlCommand(query, parameters123);



                return(RedirectToActionPermanent("Index", "Home"));
            }

            return(View(lecturer));
        }
Esempio n. 19
0
        public ActionResult Create([Bind(Include = "GroupID,ProjectID,Supervisor")] Group group)
        {
            if (String.IsNullOrWhiteSpace(group.GroupID))
            {
                TempData["null"] = "null";

                return(RedirectToAction("Index", "Groups1"));
            }
            ;
            if (group.GroupID.Any(ch => !char.IsLetterOrDigit(ch)))
            {
                TempData["letnum)"] = "letnum";
                return(RedirectToAction("Index", "Groups1"));
            }
            if (group.GroupID.Length > 6 | group.GroupID.Length < 3)
            {
                TempData["len"] = "between";
                return(RedirectToAction("Index", "Groups1"));
            }

            if (db.Groups.Any(ac => ac.GroupID.Equals(group.GroupID)))
            {
                TempData["exist)"] = "exist";
                return(RedirectToAction("Index", "Groups1"));
            }
            if (db.Groups.Any(acd => acd.ProjectID.Equals(group.ProjectID)))
            {
                TempData["NoMore)"] = "NoMore";
                return(RedirectToAction("Index", "Groups1"));
            }
            if (ModelState.IsValid)
            {
                db.Groups.Add(group);
                db.SaveChanges();
                ModelState.Clear();
                return(RedirectToAction("index"));
            }
            return(View(group));
        }
        /// <summary>
        /// Подтверждение промоакции
        /// </summary>
        /// <param name="Id">идентификатор промоакции</param>
        public ActionResult Confirm(long id)
        {
            var model = DB2.Promotions.Find(id);

            model.Status = PromotionStatus.Confirmed;
            DB2.PromotionHistory.Add(new PromotionSnapshot(CurrentUser, model, DB, DB2)
            {
                SnapshotName = "Подтверждение промоакции"
            });
            DB2.SaveChanges();
            Mails.PromotionNotification(MailType.StatusPromotion, model);

            SuccessMessage("Промоакция подтверждена");
            return(RedirectToAction("Index"));
        }
Esempio n. 21
0
        public ActionResult Edit(MailFormUi model)
        {
            var mailForm = DB2.Emails.SingleOrDefault(x => x.Id == model.Id);

            if (mailForm == null)
            {
                return(RedirectToAction("Index"));
            }

            mailForm.Body    = model.Body;
            mailForm.Subject = model.Subject;
            DB2.SaveChanges();

            return(RedirectToAction("Edit", new { id = model.Id }));
        }
        /// <summary>
        /// Отмена подтверждения промоакции
        /// </summary>
        /// <param name="Id">идентификатор промоакции</param>
        public ActionResult Reject(int id, string comment)
        {
            var model = DB2.Promotions.Find(id);

            model.Status = PromotionStatus.Rejected;
            DB2.PromotionHistory.Add(new PromotionSnapshot(CurrentUser, model, DB, DB2)
            {
                SnapshotName    = "Отклонение промоакции",
                SnapshotComment = comment
            });
            DB2.SaveChanges();
            Mails.PromotionNotification(MailType.StatusPromotion, model, comment);

            SuccessMessage("Промоакция отклонена");
            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public ActionResult DeleteFile(List <int> ids)
        {
            if (ids == null || !ids.Any())
            {
                return(RedirectToAction("Index"));
            }

            var files = DB2.MediaFiles.Where(x => ids.Contains(x.Id));

            foreach (var file in files)
            {
                DB2.MediaFiles.Remove(file);
            }
            DB2.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 24
0
        public ActionResult Create(News news)
        {
            if (!ModelState.IsValid)
            {
                return(View(news));
            }

            var user = DB2.Users.Find(CurrentUser.Id);

            if (news.Id > 0)
            {
                var model = DB2.Newses.Find(news.Id);
                // добавляем в историю изменения
                var description = "Изменена новость";
                if (!model.Enabled)
                {
                    description = "Опубликована архивная новость";
                }
                model.DatePublication = DateTime.Now;
                model.Body            = news.Body;
                model.Subject         = news.Subject;
                model.Enabled         = true;
                var history = new NewsSnapshot(model, user, description);
                DB2.NewsHistory.Add(history);
                Mails.NewsChanged(model, description, root);
                //важно, сохранить после отправки уведомления иначе не будет работать вычисление изменений
                DB2.SaveChanges();
                SuccessMessage("Изменения успешно сохранены");
            }
            else
            {
                // добавляем новость
                news.DatePublication = DateTime.Now;
                news.Enabled         = true;
                DB2.Newses.Add(news);
                DB2.SaveChanges();

                // пишем в историю
                var history = new NewsSnapshot(news, user, "Добавлена новость");
                DB2.NewsHistory.Add(history);
                DB2.SaveChanges();
                Mails.NewsChanged(news, "Добавлена новость", root);
                SuccessMessage("Новость успешно добавлена");
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 25
0
        public ActionResult DeleteNews(long id)
        {
            // отправляем новость в архив
            var news = DB2.Newses.Find(id);

            news.Enabled = false;
            DB2.SaveChanges();

            // добавляем историю изменений
            var history = new NewsSnapshot(news, DB2.Users.Find(CurrentUser.Id), "Новость отправлена в архив");

            DB2.NewsHistory.Add(history);
            DB2.SaveChanges();

            Mails.NewsChanged(news, "Новость отправлена в архив", root);
            SuccessMessage("Новость отправлена в архив");
            return(RedirectToAction("Index"));
        }
        private MediaFile SaveFile(HttpPostedFileBase src)
        {
            if (src == null)
            {
                return(null);
            }

            var file = new MediaFile(src.FileName);
            var ms   = new MemoryStream();

            src.InputStream.CopyTo(ms);

            file.ImageFile  = ms.ToArray();
            file.ImageType  = src.ContentType;
            file.ImageSize  = ms.Length;
            file.EntityType = EntityType.Promotion;
            DB2.MediaFiles.Add(file);
            DB2.SaveChanges();
            return(file);
        }
        public ActionResult Delete(long id)
        {
            var promotion = DB2.Promotions.Find(id);

            if (promotion == null)
            {
                ErrorMessage("Акция не найдена");
                return(RedirectToAction("Index"));
            }
            if (!promotion.CheckSecurity(CurrentUser))
            {
                ErrorMessage("У вас нет прав для удаления данной акции");
                return(RedirectToAction("Index"));
            }

            if (promotion.MediaFile != null)
            {
                DB2.MediaFiles.Remove(promotion.MediaFile);
                promotion.MediaFile = null;
            }

            var suppliers = DB2.PromotionsToSuppliers.Where(x => x.PromotionId == promotion.Id).ToList();

            foreach (var item in suppliers)
            {
                DB2.PromotionsToSuppliers.Remove(item);
            }
            var drugList = DB2.PromotionToDrugs.Where(x => x.PromotionId == promotion.Id).ToList();

            foreach (var item in drugList)
            {
                DB2.PromotionToDrugs.Remove(item);
            }

            DB2.Promotions.Remove(promotion);
            DB2.SaveChanges();
            SuccessMessage("Акция удалена");
            return(RedirectToAction("Index"));
        }
        private long ChangePromotion(PromotionUi model)
        {
            var promotion       = DB2.Promotions.Find(model.Id);
            var promotionToDrug = promotion.PromotionToDrug.ToList();

            foreach (var item in promotionToDrug)
            {
                var drugExsist = model.DrugList.Any(x => Convert.ToInt64(x) == item.DrugId);
                if (!drugExsist)
                {
                    DB2.PromotionToDrugs.Remove(item);
                }
            }
            foreach (var item in model.DrugList)
            {
                var drugExsist = promotion.PromotionToDrug.Any(x => x.DrugId == Convert.ToInt64(item));
                if (!drugExsist)
                {
                    PromotionToDrug newAddDrug = new PromotionToDrug()
                    {
                        DrugId      = Convert.ToInt64(item),
                        PromotionId = promotion.Id
                    };
                    DB2.PromotionToDrugs.Add(newAddDrug);
                }
            }

            var promoPromotionsToSupplier = promotion.PromotionsToSupplier.ToList();

            foreach (var item in promoPromotionsToSupplier)
            {
                var supllierExsist = model.SuppierRegions.Any(x => (ulong)Convert.ToInt64(x) == (ulong)item.SupplierId);
                if (!supllierExsist)
                {
                    DB2.PromotionsToSuppliers.Remove(item);
                }
            }
            if (model.SuppierRegions.Contains("0"))
            {
                model.SuppierRegions   = h.GetSupplierList(model.SuppierRegions.ToList().Select(x => (ulong)Convert.ToInt64(x)).ToList()).ToList().Select(x => x.Value).ToList();
                promotion.AllSuppliers = true;
            }
            else
            {
                promotion.AllSuppliers = false;
            }

            foreach (var item in model.SuppierRegions)
            {
                var supllierExsist = promotion.PromotionsToSupplier.Any(x => (ulong)x.SupplierId == (ulong)Convert.ToInt64(item));
                if (!supllierExsist)
                {
                    var addNew = new PromotionsToSupplier()
                    {
                        SupplierId  = Convert.ToInt64(item),
                        PromotionId = promotion.Id
                    };
                    promotion.PromotionsToSupplier.Add(addNew);
                }
            }

            ulong regionMask = 0;

            if (model.RegionList.Count() == 1)
            {
                regionMask = (ulong)Convert.ToInt64(model.RegionList.First());
            }
            else
            {
                regionMask = model.RegionList.Select(x => (ulong)Convert.ToInt64(x)).Aggregate((y, z) => y | z);
            }

            promotion.RegionMask = (long)regionMask;
            promotion.Name       = model.Name;
            promotion.Annotation = model.Annotation;
            promotion.Begin      = Convert.ToDateTime(model.Begin);
            promotion.End        = Convert.ToDateTime(model.End);
            promotion.Enabled    = true;
            promotion.Status     = PromotionStatus.New;
            promotion.Author     = DB2.Users.Find(CurrentUser.Id);

            var file = SaveFile(model.File);

            if (file != null)
            {
                promotion.MediaFile = file;
            }
            else if (model.PromotionFileId != null)
            {
                promotion.MediaFile = DB2.MediaFiles.Find(model.PromotionFileId.Value);
            }
            DB2.PromotionHistory.Add(new PromotionSnapshot(CurrentUser, promotion, DB, DB2));
            DB2.SaveChanges();
            Mails.PromotionNotification(MailType.EditPromotion, promotion);
            return(promotion.Id);
        }
        private long SaveNewPromotion(PromotionUi model)
        {
            var file       = SaveFile(model.File);
            var regionMask = model.RegionList.Select(x => (ulong)Convert.ToInt64(x)).Aggregate((y, z) => y | z);

            if (file == null)
            {
                if (model.PromotionFileId != null)
                {
                    file = DB2.MediaFiles.Find(model.PromotionFileId.Value);
                }
            }

            var promotion = new Promotion(CurrentUser)
            {
                Name       = model.Name,
                Annotation = model.Annotation,
                Begin      = Convert.ToDateTime(model.Begin),
                End        = Convert.ToDateTime(model.End),
                Author     = DB2.Users.Find(CurrentUser.Id),
                MediaFile  = file,
                RegionMask = (long)regionMask,
            };

            DB2.Promotions.Add(promotion);
            DB2.SaveChanges();

            foreach (var item in model.DrugList)
            {
                var promotionToDrug = new PromotionToDrug()
                {
                    DrugId      = Convert.ToInt64(item),
                    PromotionId = promotion.Id
                };
                DB2.PromotionToDrugs.Add(promotionToDrug);
            }

            if (model.SuppierRegions.Contains("0"))
            {
                model.SuppierRegions   = h.GetSupplierList(model.SuppierRegions.ToList().Select(x => (ulong)Convert.ToInt64(x)).ToList()).ToList().Select(x => x.Value).ToList();
                promotion.AllSuppliers = true;
            }
            else
            {
                promotion.AllSuppliers = false;
            }

            foreach (var item in model.SuppierRegions)
            {
                var X = new PromotionsToSupplier()
                {
                    PromotionId = promotion.Id, SupplierId = Convert.ToInt64(item)
                };
                DB2.PromotionsToSuppliers.Add(X);
            }
            DB2.PromotionHistory.Add(new PromotionSnapshot(CurrentUser, promotion, DB, DB2)
            {
                SnapshotName = "Добавление промоакции",
            });
            DB2.SaveChanges();
            Mails.PromotionNotification(MailType.CreatePromotion, promotion);
            return(promotion.Id);
        }
        public ActionResult Create([Bind(Include = "RegistrationNo,Name,Email,ContactNo,CGPA,Avatar,CV")] Student student, HttpPostedFileBase Avatar, HttpPostedFileBase CV)
        {
            Session["UserName"]  = student.Name;
            Session["Email"]     = student.Email;
            Session["CGPA"]      = student.CGPA;
            Session["CV"]        = student.CV;
            Session["ContactNo"] = student.ContactNo;
            Session["id"]        = student.RegistrationNo;
            Session["Position"]  = "student";
            var extention1 = Path.GetExtension(Avatar.FileName);
            var extention2 = Path.GetExtension(CV.FileName);

            //Check weather the model is valid and image and also the pdf format is valid
            if (ModelState.IsValid && (extention2.Equals(".PDF") || extention2.Equals(".pdf")) && (extention1.Equals(".jpg") || extention1.Equals(".jpeg") || extention1.Equals(".GIF")))
            {
                var      fileName1 = Path.GetFileName(CV.FileName);
                var      path1     = Path.Combine(Server.MapPath("~/Content/Images2"), fileName1);
                string[] path21    = path1.Split(new string[] { "SEP\\SEP" }, StringSplitOptions.None);
                CV.SaveAs(path1);
                student.CV = path21[MvcApplication.Pr_one] + "";


                var      fileName = Path.GetFileName(Avatar.FileName);
                var      path     = Path.Combine(Server.MapPath("~/Content/Images2"), fileName);
                string[] path2    = path.Split(new string[] { "SEP\\SEP" }, StringSplitOptions.None);
                Avatar.SaveAs(path);
                student.Avatar = path2[MvcApplication.Pr_one] + "";


                Session["Avatar"] = student.Avatar;

                //if the model is valid adding the student to the DB
                db.Students.Add(student);
                db.SaveChanges();



                string        query2         = "insert into  dbo.Notification(Name,Notification,Status,Loaded) values(@a3,@a4,@a5,@a6)";
                List <object> parameterList2 = new List <object>();
                parameterList2.Add(new SqlParameter("@a3", "Auro"));
                parameterList2.Add(new SqlParameter("@a4", student.Name + "Student Been Added To the SEP Tool CUT" + student.Avatar + "CUT" + DateTime.Now.ToString("HH:mm:ss tt")));
                parameterList2.Add(new SqlParameter("@a5", 2));
                parameterList2.Add(new SqlParameter("@a6", 2));
                object[] parameters12 = parameterList2.ToArray();
                int      rs1          = db.Database.ExecuteSqlCommand(query2, parameters12);



                return(RedirectToActionPermanent("Index", "Home"));
            }
            else if (!(extention2.Equals(".PDF") || extention2.Equals(".pdf")))
            {
                TempData["error"] = "Please Use A Valid PDF";
            }
            else if (!(extention1.Equals(".jpg") || extention1.Equals(".jpeg") || extention1.Equals(".GIF")))
            {
                TempData["Ava"] = "Please Use A Valid Avatar";
            }

            return(View(student));
        }