Пример #1
0
        public ActionResult Groups(GroupModel objGroup)
        {
            ViewBag.DisciplineId = new SelectList(_repoDiscipline.GetList().ToList(), "Id", "DisciplineName", "");
            if (objGroup.DisciplineId == 0)
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any Discipline";
                return(View(objGroup));
            }
            else if (objGroup.CountryName == "Country")
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any Country";
                return(View(objGroup));
            }
            if (objGroup.ProvinceId == 0)
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any State";
                return(View(objGroup));
            }
            else
            {
                try
                {
                    Group newGroup = null;

                    if (ModelState.IsValid)
                    {
                        if (objGroup != null)
                        {
                            if (objGroup.IsNew == true)
                            {
                                objGroup.CreatedDate = DateTime.Now;
                                if (_repoUserProfile != null)
                                {
                                    objGroup.CreatedBy = _repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId).Id;
                                }
                                objGroup.IsDeleted   = false;
                                objGroup.Status      = (int)Status.Active;
                                objGroup.UserProfile = UserProfileMap.Map(_repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId));
                                newGroup             = GroupMap.Map(objGroup);
                                _repoGroup.Add(newGroup);
                                objGroup.IsNew = false;
                            }
                            else
                            {
                                if (objGroup.GroupPic != null)
                                {
                                    var entityFileModel = _repoEntityFile.GetSingle(x => x.SectionId == 2 && x.EntityId == objGroup.Id);
                                    if (entityFileModel != null)
                                    {
                                        var fileModel = _repoFile.GetSingle(x => x.Id == entityFileModel.FileId);
                                        if (fileModel != null)
                                        {
                                            _repoFile.Delete(fileModel);
                                            _repoFile.Save();
                                        }

                                        _repoEntityFile.Delete(entityFileModel);
                                        _repoEntityFile.Save();
                                    }
                                }
                                objGroup.IsDeleted = false;
                                objGroup.Status    = (int)Status.Active;
                                _repoGroup.Update(GroupMap.Map(objGroup));
                            }

                            _repoGroup.Save();


                            if (objGroup.GroupPic != null && objGroup.GroupPic.InputStream != null)
                            {
                                var file = new Models.File();

                                file.ContentType = objGroup.GroupPic.ContentType;
                                file.FileName    = objGroup.GroupPic.FileName;

                                var memoryStream = new MemoryStream();
                                objGroup.GroupPic.InputStream.CopyTo(memoryStream);

                                file.Content = memoryStream.ToArray();
                                //file.UserId = group.UserId;

                                if (file.Content == null)
                                {
                                    TempData[LeonniConstants.ErrorMessage] = "Please upload Photo";
                                    return(View(objGroup)); // RedirectToAction("Create");
                                }

                                _repoFile.Add(file);
                                _repoFile.Save();

                                EntityFileModel efModel    = new EntityFileModel();
                                var             entityFile = EntityFileMap.Map(efModel);
                                entityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Groups").Id;

                                if (objGroup.Id != 0)
                                {
                                    entityFile.EntityId = objGroup.Id;
                                }
                                else
                                {
                                    entityFile.EntityId = newGroup.Id;
                                }
                                entityFile.FileId = file.Id;
                                _repoEntityFile.Add(entityFile);
                                _repoEntityFile.Save();
                            }
                        }
                        else
                        {
                            TempData[LeonniConstants.ErrorMessage] = " Update Unsuccessful";
                            return(View(objGroup));
                        }
                        TempData[LeonniConstants.SuccessMessage] = "Group Updated Successfully";
                        return(RedirectToAction("Groups"));
                    }
                    return(View(objGroup));
                    //TempData[LeonniConstants.SuccessMessage] = " Update Successful";
                    //return RedirectToAction("Groups", new { model = objGroup });
                }
                catch (Exception e)
                {
                    TempData[LeonniConstants.ErrorMessage] = e.ToString();
                    return(View(objGroup));
                }
            }
        }
        public ActionResult Upload(string selectedFileName)
        {
            //try
            //{
            //    //long sectionId = long.Parse(fc["sectionId"]);
            //    //if (ModelState.IsValid)
            //    //{
            //        //if (objFrontModel.BannerPic != null && objFrontModel.BannerPic.InputStream != null)
            //        //{
            //            var file = new Models.File();

            //            file.ContentType = "image / jpeg";
            //            file.FileName = selectedFileName;

            //            var memoryStream = new MemoryStream();
            //            //objFrontModel.BannerPic.InputStream.CopyTo(memoryStream);
            //            var fileContent  = Request.Files[selectedFileName];
            //            var fileStream = fileContent.InputStream;
            //            file.Content = ReadFile("C:\\Users\\binesh\\Desktop\\salir.jpg"); //content;//ReadFile(content);
            //           // file.Link = objFrontModel.FileLink;

            //            _repoFile.Add(file);
            //            _repoFile.Save();

            //            EntityFileModel efModel = new EntityFileModel();
            //            var entityFile = EntityFileMap.Map(efModel);
            //            entityFile.EntityName = "advertisement";
            //            entityFile.EntityId = 0;
            //            entityFile.FileId = file.Id;
            //            _repoEntityFile.Add(entityFile);
            //            _repoEntityFile.Save();
            //        //}
            //   // }
            //            JsonResult res;
            //            string redirectUrl = "/JobDetail/Activity/";
            //            res = new JsonResult
            //            {
            //                Data = new { status = "redirectToURL", message = redirectUrl }
            //            };

            //            return res;
            //    //return Json(new { status = "success" });
            //    //return View("Front", objFrontModel);
            //}
            //catch (Exception e)
            //{
            //    return Json(new { status = "error" });
            //}
            long   newId       = 0;
            bool   success     = true;
            Stream imageStream = Request.InputStream; // The actual file stream

            try
            {
                //Save info in database

                var file = new Models.File();

                file.ContentType = "image/jpeg";// Request.Files[0].ContentType;
                file.FileName    = selectedFileName;

                var memoryStream = new MemoryStream();
                //imageStream.CopyTo(memoryStream);

                //var fileContent = Request.Files[selectedFileName];
                //var fileStream = fileContent.InputStream;
                file.Content = ToByteArray(imageStream);//ReadFile("C:\\Users\\binesh\\Desktop\\salir.jpg"); //content;//ReadFile(content);
                // file.Link = objFrontModel.FileLink;
                //file.ContentType =
                _repoFile.Add(file);
                _repoFile.Save();

                EntityFileModel efModel    = new EntityFileModel();
                var             entityFile = EntityFileMap.Map(efModel);
                //   entityFile.EntityName = "advertisement";
                entityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Advertisement").Id;
                entityFile.EntityId  = 0;
                entityFile.FileId    = file.Id;

                newId = file.Id;
                _repoEntityFile.Add(entityFile);
                _repoEntityFile.Save();
            }
            catch { success = false; }
            return(Json(new { success = success, id = newId }));
        }
Пример #3
0
        public ActionResult Profile(UserProfileModel objProfile)
        {
            if (objProfile.CategoryId == 0)
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any Category";
                return(View(objProfile));
            }
            if (objProfile.DisciplineId == 0)
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any Discipline";
                return(View(objProfile));
            }
            else if (objProfile.Sex == "Sex")
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any Sex";
                return(View(objProfile));
            }
            else if (objProfile.CountryName == "Country")
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any Country";
                return(View(objProfile));
            }
            if (objProfile.StateId == 0)
            {
                TempData[LeonniConstants.ErrorMessage] = " Please Select Any State";
                return(View(objProfile));
            }
            else
            {
                try
                {
                    ViewBag.DisciplineId = new SelectList(_repoDiscipline.GetList().ToList(), "Id", "DisciplineName", "");
                    if (ModelState.IsValid)
                    {
                        if (objProfile.IsNew == true)
                        {
                            objProfile.IsLeonniTeam = false;
                            objProfile.UserId       = CurrentUser.UserId;
                            objProfile.CreatedDate  = DateTime.Now;
                            objProfile.StatusId     = (int)Status.Active; ////Active
                            _repoUserProfile.Add(UserProfileMap.Map(objProfile));
                            _repoUserProfile.Save();
                            objProfile.Id = _repoUserProfile.GetList(x => true).Select(x => x.Id).Max();
                        }
                        else
                        {
                            if (objProfile.FileId != null)//if (objProfile.ProfilePic != null)
                            {
                                var entityFileModel = _repoEntityFile.GetSingle(x => x.SectionId == 1 && x.EntityId == objProfile.Id);
                                if (entityFileModel != null)
                                {
                                    var fileModel = _repoFile.GetSingle(x => x.Id == entityFileModel.FileId);

                                    if (fileModel != null)
                                    {
                                        _repoFile.Delete(fileModel);
                                        _repoFile.Save();
                                    }
                                    if (entityFileModel != null)
                                    {
                                        _repoEntityFile.Delete(entityFileModel);
                                        _repoEntityFile.Save();
                                    }
                                }
                            }
                            objProfile.UserId       = CurrentUser.UserId;
                            objProfile.ModifiedDate = DateTime.Now;
                            _repoUserProfile.Update(UserProfileMap.Map(objProfile));
                            _repoUserProfile.Save();
                        }

                        if (objProfile.FileId != null)
                        //if (objProfile.ProfilePic != null && objProfile.ProfilePic.InputStream != null)
                        {
                            ////////Delete the existing entity and file
                            ////EntityFileModel objEntityFile = EntityFileMap.Map(_repoEntityFile.GetSingle(x => x.SectionId == 1 && x.EntityId == objProfile.Id));

                            ////Leonni.Models.File objFile = _repoFile.GetSingle(x => x.Id == objEntityFile.FileId);
                            ////_repoFile.Delete(objFile);
                            ////_repoFile.Save();
                            ////var obj1 = EntityFileMap.Map(objEntityFile);
                            ////_repoEntityFile.Delete(EntityFileMap.Map(objEntityFile));
                            ////_repoEntityFile.Save();

                            /////Delete the existing file
                            /////

                            //var file = new Models.File();

                            //file.ContentType = objProfile.ProfilePic.ContentType;
                            //file.FileName = objProfile.ProfilePic.FileName;

                            //var memoryStream = new MemoryStream();
                            //objProfile.ProfilePic.InputStream.CopyTo(memoryStream);

                            //Image obj = Image.FromStream(objProfile.ProfilePic.InputStream, true, true);

                            //file.Content = memoryStream.ToArray();
                            //file.Height = obj.Height;
                            //file.Width = obj.Width;

                            //if (file.Content == null)
                            //{
                            //    TempData[LeonniConstants.ErrorMessage] = "Please upload Photo";
                            //    return View(objProfile); // RedirectToAction("Create");
                            //}

                            //_repoFile.Add(file);
                            //_repoFile.Save();

                            //EntityFileModel objEntityFile = new EntityFileModel();
                            //objEntityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Users").Id;
                            //objEntityFile.EntityId = objProfile.Id;
                            //objEntityFile.FileId = file.Id;
                            //_repoEntityFile.Add(EntityFileMap.Map(objEntityFile));
                            //_repoEntityFile.Save();

                            EntityFileModel efModel    = new EntityFileModel();
                            var             entityFile = EntityFileMap.Map(efModel);

                            entityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Users").Id;
                            entityFile.EntityId  = objProfile.Id;
                            entityFile.FileId    = objProfile.FileId;

                            _repoEntityFile.Add(entityFile);
                            _repoEntityFile.Save();
                        }
                    }
                    else
                    {
                        TempData[LeonniConstants.ErrorMessage] = " Update Unsuccessful";
                        return(View(objProfile));
                    }
                    TempData[LeonniConstants.SuccessMessage] = "Profile Updated Successfully";
                    return(RedirectToAction("Profile"));
                }
                catch (Exception e)
                {
                    TempData[LeonniConstants.ErrorMessage] = e.ToString();
                    return(View(objProfile));
                }
            }
        }