Example #1
0
        public ActionResult Add(AddUserViewModel form)
        {
            if (!ModelState.IsValid)
            {
                return(View(form));
            }
            //Create the mapping between AutomobileDM to CarVM
            Mapper.CreateMap <AddUserViewModel, ApplicationUser>();
            //Perform the conversion and fetch the destination view model
            var newAlumni = Mapper.Map <ApplicationUser>(form);

            newAlumni.UpdateDatetime = DateTime.Now;
            if (string.IsNullOrEmpty(form.HeaderImage))
            {
                newAlumni.HeaderImage = "/images/alumni/default_profile.png";
            }
            try
            {
                _context.AddOneEntity <ApplicationUser>(newAlumni);
            }
            catch (Exception)
            {
                ModelState.AddModelError(string.Empty, "Please check if your student name and id are same with others");
                return(View(form));
            }
            return(RedirectToAction <AlumniController>(c => c.Index()).WithInfo("Alumni created!"));
        }
Example #2
0
 public ActionResult Add(WebEvent input)
 {
     input.Image       = _context.GetImage(input.Content, "event");
     input.UpdatedDate = DateTime.Now;
     _context.AddOneEntity <WebEvent>(input);
     return(RedirectToAction <WebEventController>(d => d.Index(input.LanguageId)));
 }
Example #3
0
 public ActionResult Add(WebStory input)
 {
     input.Image       = _context.GetImage(input.Content, "story");
     input.UpdatedDate = DateTime.Now;
     input.Order       = 5;
     _context.AddOneEntity <WebStory>(input);
     return(RedirectToAction <WebStoryController>(d => d.Index(input.LanguageId)));
 }
        public ActionResult Upload(UploadFileViewModel uploadFiles)
        {
            for (int i = 0; i < uploadFiles.Files.Count; i++)
            {
                var file = uploadFiles.Files[i];
                if (file == null)
                {
                    continue;
                }
                var fileName = Path.GetFileName(file.FileName);
                if (string.IsNullOrEmpty(fileName))
                {
                    return(RedirectToAction("Index"));
                }
                var ext = fileName.Substring(fileName.IndexOf(".")).ToLower();
                if (ext == ".jpg" || ext == ".png" || ext == ".bmp")
                {
                    if (file.ContentLength > 1000000)
                    {
                        continue;
                    }
                }

                var newImage = new UserFile
                {
                    OperationDate = _db.GetNzTime(),
                    Operator      = _currentUser.User.Email,
                    FileType      = ext,
                    Category      = uploadFiles.Category,
                    Name          = fileName
                };
                _db.AddOneEntity(newImage);
                _db.SaveChange();
                if (ext == ".jpg" || ext == ".png" || ext == ".bmp")
                {
                    file.SaveAs(Server.MapPath("~/images/FileLibrary/" + newImage.Id + ext));
                }
                else
                {
                    file.SaveAs(Server.MapPath("~/images/FileLibrary/" + newImage.Name));
                }
            }
            return(RedirectToAction <UploadFilesController>(d => d.Index(uploadFiles.Category)));
        }
Example #5
0
        public JsonResult _Add(long parentId, long languageId, string name)
        {
            long?menuParentId;

            if (parentId == 0)
            {
                menuParentId = null;
            }
            else
            {
                menuParentId = parentId;
            }
            var item = new WebMenu {
                ParentId = menuParentId, LanguageId = languageId, Name = name, UpdatedDate = DateTime.Now
            };

            _context.AddOneEntity <WebMenu>(item);
            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        public ActionResult UploadImage()
        {
            HttpPostedFileBase file = Request.Files[0] as HttpPostedFileBase;
            string             pic  = "";

            if (file != null)
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream, true, true))
                {
                    if (image.Width == 1385 && image.Height == 398)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var ext      = fileName.Substring(fileName.IndexOf(".") + 1).ToLower();
                        if (ext != "gif" && ext == "png" && ext == "jpg" && ext == "bmp")
                        {
                            return(Json("Sorry, you can only upload gif,png,jpg or bmp file.", JsonRequestBehavior.AllowGet));
                        }
                        if (file.ContentLength > 400000)//400k
                        {
                            return(Json("Sorry, your logo file size can not be bigger than 400k. Please upload proper size file.", JsonRequestBehavior.AllowGet));
                        }
                        pic = Guid.NewGuid().ToString() + "." + ext;
                        string path = System.IO.Path.Combine(Server.MapPath("/images/Slider/"), pic);
                        file.SaveAs(path);
                        _context.AddOneEntity <WebCarouselBackground>(new WebCarouselBackground {
                            Name = fileName, Path = "/images/Slider/" + pic
                        });
                        return(Json("done", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json("Sorry, file dimensions is wrong.", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            else
            {
                return(Json("Please select your file", JsonRequestBehavior.AllowGet));
            }
        }
Example #7
0
        public JsonResult _OperatorEdit(OperatorViewModel input)
        {
            _context.Get <ApplicationUser>(d => d.Id == input.Id).FirstOrDefault().UpdateDatetime = _context.GetNzTime();
            var opteratorRoles = _context.Get <IdentityUserRole>(d => d.UserId == input.Id).ToList();

            foreach (var item in opteratorRoles)
            {
                if (input.RolePosted != null)
                {
                    if (!input.RolePosted.ids.Any(d => d == item.RoleId))
                    {
                        var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault();
                        _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted;
                    }
                }
                else
                {
                    var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault();
                    _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted;
                }
            }
            _context.SaveChange();
            if (input.RolePosted != null)
            {
                foreach (var item in input.RolePosted.ids)
                {
                    if (!opteratorRoles.Any(d => d.RoleId == item))
                    {
                        _context.AddOneEntity <IdentityUserRole>(new IdentityUserRole {
                            UserId = input.Id, RoleId = item
                        });
                    }
                }
            }
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Example #8
0
        public ActionResult Add(WebLanguage input)
        {
            #region create new data
            var newLanguage = new WebLanguage {
                Name = input.Name
            };
            //menu
            foreach (var level1 in _context.Get <WebMenu>(d => d.LanguageId == 1 && d.ParentId == null).ToList())
            {
                var Newlevel1 = new WebMenu()
                {
                    Name = level1.Name, Content = level1.Content, Link = level1.Link, Order = level1.Order
                };
                foreach (var level2 in _context.Get <WebMenu>(d => d.LanguageId == 1 && d.ParentId == level1.Id).ToList())
                {
                    var Newlevel2 = new WebMenu()
                    {
                        Name = level2.Name, Content = level2.Content, Link = level2.Link, Order = level2.Order
                    };
                    foreach (var level3 in _context.Get <WebMenu>(d => d.LanguageId == 1 && d.ParentId == level2.Id).ToList())
                    {
                        Newlevel2.WebMenuChildren.Add(new WebMenu()
                        {
                            Name = level3.Name, Content = level3.Content, Link = level3.Link, Order = level3.Order
                        });
                    }
                    Newlevel1.WebMenuChildren.Add(Newlevel2);
                }
                newLanguage.WebMenus.Add(Newlevel1);
            }
            //college
            var college = _context.FindDetail <College>(1);
            _context.EntityCloneNew(college);
            newLanguage.College = college;

            //carousel
            foreach (var item in _context.Get <WebCarousel>(d => d.LanguageId == 1).ToList())
            {
                _context.EntityCloneNew(item);
                newLanguage.WebCarousels.Add(item);
            }
            //newsType
            foreach (var item in _context.Get <WebNewsType>(d => d.LanguageId == 1).Include(d => d.WebNews).ToList())
            {
                _context.EntityCloneNew(item);
                foreach (var news in item.WebNews)
                {
                    _context.EntityCloneNew(news);
                }
                newLanguage.WebNewsTypes.Add(item);
            }
            //events
            foreach (var item in _context.Get <WebEvent>(d => d.LanguageId == 1).ToList())
            {
                _context.EntityCloneNew(item);
                newLanguage.WebEvents.Add(item);
            }
            //JobType
            foreach (var item in _context.Get <WebJobType>(d => d.LanguageId == 1).ToList())
            {
                _context.EntityCloneNew(item);
                newLanguage.WebJobTypes.Add(item);
            }
            //Departments
            foreach (var item in _context.Get <WebDepartment>(d => d.LanguageId == 1).Include(d => d.WebStaff).Include(d => d.WebStories).Include(d => d.WebStudents).ToList())
            {
                _context.EntityCloneNew(item);
                foreach (var staff in item.WebStaff)
                {
                    _context.EntityCloneNew(staff);
                }
                foreach (var story in item.WebStories)
                {
                    _context.EntityCloneNew(story);
                }
                foreach (var student in item.WebStudents)
                {
                    _context.EntityCloneNew(student);
                }
                newLanguage.WebDepartment.Add(item);
            }
            //userful link
            foreach (var item in _context.Get <WebUsefulLink>(d => d.LanguageId == 1).ToList())
            {
                _context.EntityCloneNew(item);
                newLanguage.WebUsefulLinks.Add(item);
            }
            _context.AddOneEntity(newLanguage);
            #endregion
            #region update languageId
            //newsType
            var languageId = newLanguage.Id;
            foreach (var item in _context.Get <WebNewsType>(d => d.LanguageId == languageId).Include(d => d.WebNews).ToList())
            {
                foreach (var news in item.WebNews)
                {
                    news.LanguageId = languageId;
                }
            }
            //Departments
            foreach (var item in _context.Get <WebDepartment>(d => d.LanguageId == languageId).Include(d => d.WebStaff).Include(d => d.WebStories).Include(d => d.WebStudents).ToList())
            {
                foreach (var staff in item.WebStaff)
                {
                    staff.LanguageId = languageId;
                }
                foreach (var story in item.WebStories)
                {
                    story.LanguageId = languageId;
                }
                //foreach (var student in item.WebStudents)
                //{

                //}
            }
            _context.SaveChange();
            #endregion
            return(RedirectToAction <WebLanguageController>(d => d.Index()));
        }
 public ActionResult Add(WebCarousel input)
 {
     input.UpdatedDate = DateTime.Now;
     _context.AddOneEntity <WebCarousel>(input);
     return(RedirectToAction <WebCarouselController>(d => d.Index(input.LanguageId)));
 }
Example #10
0
 public ActionResult Add(WebDepartment input)
 {
     _context.AddOneEntity <WebDepartment>(input);
     return(RedirectToAction <WebDepartmentController>(d => d.Index(input.LanguageId)));
 }
 public ActionResult Add(WebNewsType input)
 {
     _context.AddOneEntity <WebNewsType>(input);
     return(RedirectToAction <WebNewsTypesController>(d => d.Index(input.LanguageId)));
 }