Ejemplo n.º 1
0
        public JsonResult CreateCategory(string CCName, string BackImage, string BackLeft, string BackTop, string IsEditPic) //ModelCourseCategory ModCorsCat)
        {
            try
            {
                using (IwillDbEntities Dbc = new IwillDbEntities())
                {
                    if (IsEditPic == "false")
                    {
                        var data         = new CourseCategory();
                        var TempLocation = Server.MapPath("~/Images/Temp/" + BackImage);
                        var DestLocation = Server.MapPath("~/Images/UserImages/" + BackImage);
                        System.IO.File.Copy(TempLocation, DestLocation);
                        System.IO.File.Delete(TempLocation);

                        data.CCName      = CCName;
                        data.CImagePath  = BackImage;
                        data.BackImgLeft = Convert.ToInt32(BackLeft);
                        data.BackImgTop  = Convert.ToInt32(BackTop);
                        data.CreatedOn   = DateTime.Now;
                        data.CreatedBy   = Helper.User.UID;
                        data.IsActive    = true;
                        Dbc.CourseCategories.Add(data);
                        Dbc.SaveChanges();
                        TempData["success"] = "Course Category Back Image has been Created";

                        return(Json("saved", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var TempLocation = Server.MapPath("~/Images/Temp/" + BackImage);
                        var DestLocation = Server.MapPath("~/Images/UserImages/" + BackImage);
                        System.IO.File.Copy(TempLocation, DestLocation);
                        System.IO.File.Delete(TempLocation);

                        var data = Dbc.CourseCategories.Where(i => i.CCName.ToLower() == CCName.ToLower().Trim() && i.CreatedBy == Helper.User.UID).FirstOrDefault();
                        if (data != null)
                        {
                            data.CImagePath  = BackImage;
                            data.BackImgLeft = Convert.ToInt32(BackLeft);
                            data.BackImgTop  = Convert.ToInt32(BackTop);
                            data.CreatedOn   = DateTime.Now;
                            Dbc.SaveChanges();
                            //TempData["success"] = "Course Category Back Image has been updated";
                            return(Json("updated", JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            throw new Exception("data not found to update course category");
                        }
                    }
                }


                //return Json("Error: not deleted", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return(Json("Error: on save<br> " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult InsertQuesForUserRegistration(ModelUserRegQuestion mod)
        {
            using (var transaction = DBC.Database.BeginTransaction())
            {
                try
                {
                    if (mod == null)
                    {
                        throw new Exception("There is no Questionairs to save ");
                    }


                    var QuestionObj = new UserQuestion()
                    {
                        UQuestion = mod.UQuestion,
                        FkUQType  = mod.FkUQType,
                        IsStudent = mod.IsStudent,
                        IsActive  = mod.IsActive == null ? true : mod.IsActive,
                        CreatedOn = DateTime.Now,
                        CreatedBy = Helper.User.UID
                    };

                    DBC.UserQuestions.Add(QuestionObj);
                    DBC.SaveChanges();

                    if (mod.FkUQType != 2)
                    {
                        var QuestionID = DBC.UserQuestions.Local[0].UQID;
                        foreach (var item in mod.UserQuestionDetail)
                        {
                            var ObjDetail = new UserQuestionDetail()
                            {
                                QuesOptionName = item.QuesOptionName,
                                IsRight        = item.IsRight,
                                IsActive       = item.IsActive == null ? true : item.IsActive,
                                FkQID          = QuestionID,
                            };
                            DBC.UserQuestionDetails.Add(ObjDetail);
                            DBC.SaveChanges();
                        }
                    }

                    TempData["success"] = "Question has been created";
                    transaction.Commit();
                    return(RedirectToAction("ViewCreateQuesForUserRegistration", "UserRegQuestion"));
                }

                catch (Exception ex)
                {
                    transaction.Rollback();
                    ViewData["Error"] = "Error: to Save data " + ex.Message;
                    return(RedirectToAction("ViewCreateQuesForUserRegistration", "UserRegQuestion"));
                }
            }
        }
Ejemplo n.º 3
0
        public JsonResult UpdateBackImagePostion(string CategoryName, string BCimgTOP, string BCimgLeft)
        {
            try
            {
                using (IwillDbEntities Dbc = new IwillDbEntities())
                {
                    //DP image  upload on server

                    var data = Dbc.CourseCategories.Where(i => i.CreatedBy == Helper.User.UID && i.CCName.ToLower() == CategoryName.ToLower().Trim()).FirstOrDefault();
                    if (data != null)
                    {
                        data.BackImgTop  = Convert.ToInt32(BCimgTOP);
                        data.BackImgLeft = Convert.ToInt32(BCimgLeft);
                        Dbc.SaveChanges();
                    }
                    else
                    {
                        return(Json("Error: invalid Pic Name found", JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json("updated", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json("Error: on update<br> " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult UpdateUserRegesterQuestionOption(ModelUserQuestionDetail GetUserQuesOption)
        {
            try
            {
                using (IwillDbEntities data = new IwillDbEntities())
                {
                    var UserQuestionOption = data.UserQuestionDetails.Where(i => i.UQDID == GetUserQuesOption.UQDID).FirstOrDefault();
                    if (UserQuestionOption == null)
                    {
                        return(Json("No Record Found", JsonRequestBehavior.AllowGet));
                    }

                    UserQuestionOption.QuesOptionName = GetUserQuesOption.QuesOptionName;

                    int r = data.SaveChanges();

                    if (r >= 0)
                    {
                        TempData["success"] = "Question option has Successfully updated";
                        TempData["UQDID"]   = GetUserQuesOption.UQDID;
                        return(Json("Record Updated Successfully", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        //ViewData["Error"]= "Error: on updating the question";
                        return(Json("error on inserting", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                ViewData["Error"] = "Error: " + ex.Message;
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult ActivateQuestionDetailOption(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    throw new Exception("Question ID Requried");
                }

                Int64 UQDID = Convert.ToInt64(id);


                using (IwillDbEntities data = new IwillDbEntities())
                {
                    var UserQuestOption = data.UserQuestionDetails.Where(i => i.UQDID == UQDID).FirstOrDefault();
                    if (UserQuestOption == null)
                    {
                        return(Json("No Record Found", JsonRequestBehavior.AllowGet));
                    }


                    Int64 QID  = Convert.ToInt64(UserQuestOption.FkQID);
                    var   Ques = DBC.UserQuestions.Where(i => i.UQID == QID).FirstOrDefault();

                    if (Ques == null)
                    {
                        return(Json("No Question Detail Found", JsonRequestBehavior.AllowGet));
                    }

                    if (Ques.FkUQType == 1 && UserQuestOption.IsRight == true)
                    {
                        return(Json("Cannot Activated MCQz option, because its value is true", JsonRequestBehavior.AllowGet));
                    }


                    UserQuestOption.IsActive = true;

                    int r = data.SaveChanges();

                    if (r >= 0)
                    {
                        TempData["success"] = "Question Option has Successfully Activated";
                        TempData["UQDID"]   = id;
                        return(Json("Question Option has Successfully Activated", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        //ViewData["Error"]= "Error: on updating the question";
                        return(Json("error on Activating option", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                ViewData["Error"] = "Error: " + ex.Message;
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult DeactivateQuestion(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    throw new Exception("Question ID Requried");
                }

                //if (string.IsNullOrEmpty(UQID))
                //    throw new Exception("Activation can not be empty");

                Int64 QID = Convert.ToInt64(id);
                //bool IsActivated = Convert.ToBoolean(IsActivate);

                using (IwillDbEntities data = new IwillDbEntities())
                {
                    var UserQuestion = data.UserQuestions.Where(i => i.UQID == QID).FirstOrDefault();
                    if (UserQuestion == null)
                    {
                        return(Json("No Record Found", JsonRequestBehavior.AllowGet));
                    }

                    UserQuestion.IsActive = false;

                    int r = data.SaveChanges();
                    TempData["UQID"] = id;

                    if (r >= 0)
                    {
                        TempData["success"] = "Question has Successfully Deactivated";
                        TempData["UQID"]    = id;
                        return(Json("Record Deactivated Successfully", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        //ViewData["Error"]= "Error: on updating the question";
                        return(Json("error on Deactivating", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                ViewData["Error"] = "Error: " + ex.Message;
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 7
0
        public JsonResult RemoveBackgroundPic(string CategoryName, string FileName, string IsBackPicEdit)
        {
            try
            {
                using (IwillDbEntities Dbc = new IwillDbEntities())
                {
                    if (IsBackPicEdit == "true")
                    {
                        var BackPic        = Dbc.CourseCategories.Where(i => i.CreatedBy == Helper.User.UID && i.CCName.ToLower() == CategoryName.ToLower().Trim()).FirstOrDefault();
                        var OldPicLocation = Server.MapPath("~/Images/UserImages/" + BackPic.CImagePath);
                        System.IO.File.Delete(OldPicLocation);

                        BackPic.CImagePath  = null;
                        BackPic.BackImgLeft = null;
                        BackPic.BackImgTop  = null;
                    }
                    else
                    {
                        var fullPath = Server.MapPath("~/Images/Temp/" + FileName);

                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);

                            var tempPic = Dbc.TempPics.Where(i => i.TempPicName == FileName).FirstOrDefault();
                            Dbc.TempPics.Remove(tempPic);
                        }
                        else
                        {
                            return(Json("Error: not deleted", JsonRequestBehavior.AllowGet));
                        }
                    }
                    Dbc.SaveChanges();
                    return(Json("deleted", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json("Error: on delete<br> " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 8
0
        public JsonResult CourseCategoryFileUpload()
        {
            var path = "";

            try
            {
                string CurrentUserIP = Request.UserHostAddress;
                // CheckUserPicUploadCount(UserIP);
                using (IwillDbEntities Dbc = new IwillDbEntities())
                {
                    var count = Dbc.TempPics.Where(i => i.UserIP == CurrentUserIP && EntityFunctions.TruncateTime(i.CreatedOn.Value) == EntityFunctions.TruncateTime(DateTime.Now) && i.CreatedBy == Helper.User.UID).ToList().Count;

                    if (count > 10)
                    {
                        return(Json("Create Category, image upload limit exceeded", JsonRequestBehavior.AllowGet));
                    }
                }
                string fileName = "";
                string Ext      = "";
                string PicPath  = "";
                if (Request.Files.Count == 0)
                {
                    return(Json("nofiles", JsonRequestBehavior.AllowGet));
                }

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    fileName = Path.GetFileName(file.FileName);
                    Ext      = Path.GetExtension(file.FileName);

                    //fileName = "UserImg_" + Guid.NewGuid().ToString().Trim() + Ext;
                    fileName = Guid.NewGuid().ToString().Trim() + Ext;

                    var      fileLocation   = Server.MapPath("~/Images/Temp/");
                    FileInfo fileDiresctory = new FileInfo(fileLocation);
                    if (!fileDiresctory.Exists)
                    {
                        fileDiresctory.Directory.Create();
                    }

                    path = Path.Combine(fileLocation, fileName);
                    if (!System.IO.File.Exists(path))
                    {
                        string aa = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                        file.SaveAs(path);
                        using (IwillDbEntities Dbc = new IwillDbEntities())
                        {
                            var tempPic = new TempPic()
                            {
                                TempPicName = fileName, CreatedOn = DateTime.Now, CreatedBy = Helper.User.UID, UserIP = Request.UserHostAddress
                            };

                            Dbc.TempPics.Add(tempPic);
                            Dbc.SaveChanges();
                        }
                    }
                    else
                    {
                        return(Json("file already exists", JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json("saved^" + fileName, JsonRequestBehavior.AllowGet));
                //return Json("saved^", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return(Json("notsaved " + path, JsonRequestBehavior.AllowGet));
            }
        }