Exemple #1
0
 public ActionResult Translate(Enums.Pages page, Languages lang, string tagId)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         if (lang == Languages.Mk)
         {
             return(Json(db.GetTranslate((int)page, tagId).ToList().Select(x => new
             {
                 Id = x.Id,
                 Title = x.TitleMk,
                 Description = x.DescriptionMk,
                 ImgPath = x.ImgPath
             }), JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(db.GetTranslate((int)page, tagId).ToList().Select(x => new
             {
                 Id = x.Id,
                 Title = x.TitleFr,
                 Description = x.DescriptionFr,
                 ImgPath = x.ImgPath
             }), JsonRequestBehavior.AllowGet));
         }
     }
 }
Exemple #2
0
 public ActionResult GalleryDetails(int masterId, Languages lang)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         if (lang == Languages.Mk)
         {
             return(Json(db.GalleryDetails.Where(x => x.GalleryMasterId == masterId).Select(x => new
             {
                 id = x.Id,
                 title = x.TitleMk,
                 uploaded = x.SysDate,
                 x.TitleFr,
                 x.TitleMk
             }).ToList(), JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(db.GalleryDetails.Where(x => x.GalleryMasterId == masterId).Select(x => new
             {
                 id = x.Id,
                 title = x.TitleFr,
                 uploaded = x.SysDate,
                 x.TitleFr,
                 x.TitleMk
             }).ToList(), JsonRequestBehavior.AllowGet));
         }
     }
 }
Exemple #3
0
        public ActionResult UpdateSubGaleryImage(GalleryDetails item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    HttpPostedFileBase file = Request.Files[0];
                    if (file.ContentLength > 0)
                    {
                        var path = Server.MapPath("~/Images/Gallery/Details/" + item.Id + ".jpg");
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        file.SaveAs(path);
                    }

                    var obj = db.GalleryDetails.Find(item.Id);
                    db.Entry(obj).CurrentValues.SetValues(item);
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(item.GalleryMasterId, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
 public ActionResult GetUsersTotal(string search)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         return(Json(db.GetUsersTotal(search).ToList(), JsonRequestBehavior.AllowGet));
     }
 }
Exemple #5
0
 public ActionResult GetPagingUsers(int pageIndex, int itemsPerPage, string search)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         return(Json(db.GetUsers(pageIndex, itemsPerPage, search).Select(e => new { e.Id, e.Name, e.LastName, e.UserName, e.Email, e.Active }).ToList(), JsonRequestBehavior.AllowGet));
     }
 }
Exemple #6
0
 public ActionResult CalendarEvents(Languages lang)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         if (lang == Languages.Mk)
         {
             return(Json(db.Calendar.Select(x => new
             {
                 id = x.Id,
                 title = x.TitleMk,
                 description = x.DescriptionMk.Equals(null) ? "" : x.DescriptionMk,
                 start = x.start,
                 end = x.end
             }).ToList(), JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(db.Calendar.Select(x => new
             {
                 id = x.Id,
                 title = x.TitleFr,
                 description = x.DescriptionFr.Equals(null) ? "" : x.DescriptionFr,
                 start = x.start,
                 end = x.end
             }).ToList(), JsonRequestBehavior.AllowGet));
         }
     }
 }
Exemple #7
0
 public ActionResult ToggleUpdateActiveUser(string id, bool active)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         return(Json(db.UpdateActiveUser(id, active), JsonRequestBehavior.AllowGet));
     }
 }
Exemple #8
0
        public ActionResult SaveImages(GalleryDetails item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    if (!Directory.Exists(Server.MapPath("~/Images/Gallery/Details")))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/Images/Gallery/Details"));
                    }

                    HttpPostedFileBase file = Request.Files[0];

                    var i = db.GalleryDetails.Add(item);
                    db.SaveChanges();
                    string extension = Path.GetExtension(file.FileName);

                    var path = Path.Combine(Server.MapPath("~/Images/Gallery/Details/"), i.Id + ".jpg");

                    file.SaveAs(path);
                }
            }
            catch
            {
                res = false;
            }
            return(Json(item.GalleryMasterId, JsonRequestBehavior.AllowGet));
        }
Exemple #9
0
        public ActionResult GetUser(string id)
        {
            using (AbcUEMDbEntities db = new AbcUEMDbEntities())
            {
                var user = (from x in db.AspNetUsers where x.UserName == User.Identity.Name select x.Id).FirstOrDefault();

                if (id == null)
                {
                    id = user;
                }

                var query = (from u in db.AspNetUsers
                             join ur in db.AspNetUserRoles on u.Id equals ur.UserId
                             join r in db.AspNetRoles on ur.RoleId equals r.Id
                             where u.Id == id
                             select new
                {
                    Id = u.Id,
                    Name = u.Name,
                    LastName = u.LastName,
                    UserName = u.UserName,
                    Email = u.Email,
                    Active = u.Active
                }).FirstOrDefault();

                return(Json(query, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #10
0
 public ActionResult GetContent(Translates item)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         return(Json(db.Translates.Where(x => x.Id == item.Id).FirstOrDefault(), JsonRequestBehavior.AllowGet));
     }
 }
Exemple #11
0
        public ActionResult DeleteGalery(GalleryMaster item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    db.GalleryMaster.Remove(db.GalleryMaster.Find(item.Id));
                    var pathMaster = Server.MapPath("~/Images/Gallery/Master/" + item.Id + ".jpg");
                    if (System.IO.File.Exists(pathMaster))
                    {
                        System.IO.File.Delete(pathMaster);
                    }
                    foreach (var i in db.GalleryDetails.Where(x => x.GalleryMasterId == item.Id))
                    {
                        var pathDetails = Server.MapPath("~/Images/Gallery/Details/" + i.Id + ".jpg");
                        if (System.IO.File.Exists(pathDetails))
                        {
                            System.IO.File.Delete(pathDetails);
                        }
                        db.GalleryDetails.Remove(db.GalleryDetails.Find(i.Id));
                    }
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #12
0
 public ActionResult GetCalendarEvent(Calendar item)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         return(Json(db.Calendar.Where(x => x.Id == item.Id).FirstOrDefault(), JsonRequestBehavior.AllowGet));
     }
 }
Exemple #13
0
        public ActionResult UpdateCalendarEvent(Calendar item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    if (item.start == null || item.end == null)
                    {
                        var obj = db.Calendar.Find(item.Id);
                        obj.TitleFr       = item.TitleFr;
                        obj.TitleMk       = item.TitleMk;
                        obj.DescriptionFr = item.DescriptionFr;
                        obj.DescriptionMk = item.DescriptionMk;
                        db.SaveChanges();
                    }
                    else
                    {
                        var obj = db.Calendar.Find(item.Id);
                        obj.start = item.start;
                        obj.end   = item.end;
                        db.SaveChanges();
                    }
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
 public ActionResult Roles()
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         var allRoles = db.AspNetRoles.Select(e => new { e.Id, e.Name, e.Order }).ToList();
         return(Json(allRoles, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #15
0
        public ActionResult GetUserRoles(string id)
        {
            using (AbcUEMDbEntities db = new AbcUEMDbEntities())
            {
                var roles = (from ur in db.AspNetUserRoles
                             join r in db.AspNetRoles on ur.RoleId equals r.Id
                             where ur.UserId == id
                             select new
                {
                    RoleID = ur.RoleId,
                    RoleName = r.Name
                }).ToList();

                return(Json(roles, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #16
0
        public ActionResult FirstRegister()
        {
            using (AbcUEMDbEntities db = new AbcUEMDbEntities())
            {
                var query = db.AspNetUsers.Count();

                if (query > 0)
                {
                    return(RedirectToAction("Login"));
                }
                else
                {
                    return(View());
                }
            }
        }
Exemple #17
0
 public ActionResult DeleteContent(Translates item)
 {
     using (AbcUEMDbEntities db = new AbcUEMDbEntities())
     {
         bool res = true;
         try
         {
             db.Translates.Remove(db.Translates.Find(item.Id));
             db.SaveChanges();
         }
         catch
         {
             res = false;
         }
         return(Json(res, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #18
0
        public ActionResult AddContent(Translates item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    db.Translates.Add(item);
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #19
0
        public ActionResult DeleteCalendarEvent(Calendar item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    db.Calendar.Remove(db.Calendar.Find(item.Id));
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #20
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            using (AbcUEMDbEntities db = new AbcUEMDbEntities())
            {
                var userActive = (from x in db.AspNetUsers where x.UserName == model.Username select x.Active).FirstOrDefault();

                if (userActive == true)
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(model));
                    }

                    // This doesn't count login failures towards account lockout
                    // To enable password failures to trigger account lockout, change to shouldLockout: true
                    var result = await SignInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, shouldLockout : false);

                    switch (result)
                    {
                    case SignInStatus.Success:
                        return(RedirectToLocal(returnUrl));

                    case SignInStatus.LockedOut:
                        return(View("Lockout"));

                    case SignInStatus.RequiresVerification:
                        return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

                    case SignInStatus.Failure:
                        ModelState.AddModelError("", "Invalid login attempt.");
                        return(View(model));

                    default:
                        ModelState.AddModelError("", "Invalid login attempt.");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return(View(model));
                }
            }
        }
Exemple #21
0
        public ActionResult UpdateContent(Translates item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    var obj = db.Translates.Find(item.Id);
                    db.Entry(obj).CurrentValues.SetValues(item);
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #22
0
        //---Returns Username of client based on received email.
        public string GetUserName(string email)
        {
            var name = "";

            using (AbcUEMDbEntities db = new AbcUEMDbEntities())
            {
                name = (from x in db.AspNetUsers
                        where x.Email == email
                        select x.UserName).FirstOrDefault();

                //If the username don't exists based on received email, return the non-existing email.
                //This function is created for ResetPassword method check - UserManager.FindByNameAsync(GetUserName(model.Email)),
                //because it cannot receive null, we return the entered email.
                if (name == null)
                {
                    return(email);
                }

                return(name);
            }
        }
Exemple #23
0
        public async Task <ActionResult> UpdateUser(RegisterViewModel model)
        {
            var res = false;

            try
            {
                if (ModelState.IsValid)
                {
                    //Get userId based of logged user identity name
                    using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                    {
                        var userId = (from x in db.AspNetUsers where x.UserName == User.Identity.Name select x.Id).FirstOrDefault();

                        //If received value from viewModel of model.Id is null, then assign logged userId value to model.Id
                        //This is because of editing of logged user, it can take the Id of the logged user.
                        if (model.Id == null)
                        {
                            model.Id = userId;

                            string newUserName = model.UserName;

                            //When updating username of logged user, we need to remove the claimIdentity of logged userName, and
                            //then add new claimIdentity with the updated username
                            var identity = new ClaimsIdentity(User.Identity);
                            identity.RemoveClaim(identity.FindFirst(identity.NameClaimType));
                            identity.AddClaim(new Claim(identity.NameClaimType, newUserName));
                            AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
                                                                                    (new ClaimsPrincipal(identity), new AuthenticationProperties {
                                IsPersistent = false
                            });
                        }
                    }

                    ApplicationUser user = UserManager.FindById(model.Id);
                    user.UserName   = model.UserName;
                    user.Name       = model.Name;
                    user.MiddleName = model.MiddleName;
                    user.Email      = model.Email;
                    user.LastName   = model.LastName;

                    //Hashing received password from the model
                    if (model.ConfirmPassword != null)
                    {
                        var newPasswordHash = UserManager.PasswordHasher.HashPassword(model.ConfirmPassword);
                        user.PasswordHash = newPasswordHash;
                    }

                    //Create directory with attached photo saved in into the directory
                    if (model.Photo != null)
                    {
                        var fileName      = model.UserName + ".png";
                        var path          = Path.Combine(Server.MapPath("~/Images/Users/"), fileName);
                        var pathToResized = Path.Combine(Server.MapPath("~/Images/Users/"), "resized-" + fileName);
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        if (System.IO.File.Exists(pathToResized))
                        {
                            System.IO.File.Delete(pathToResized);
                        }
                        var NewfileName      = model.UserName + ".png";
                        var toPath           = Path.Combine(Server.MapPath("~/Images/Users/"), NewfileName);
                        var resPathToResized = Path.Combine(Server.MapPath("~/Images/Users/"), "resized-" + NewfileName);
                        model.Photo.SaveAs(toPath);
                        Bitmap resizedImage = resizeImage(30, 30, toPath);
                        resizedImage.Save(resPathToResized);
                    }

                    var update = await UserManager.UpdateAsync(user);

                    res = true;
                }
            }
            catch
            {
                res = false;
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }