public ActionResult CreateDiscussion(CreateThreadInfo thread, IEnumerable <HttpPostedFileBase> Images)
 {
     WingS.Models.Thread newThread = null;
     //Add thread to DB
     using (var db = new ThreadDAL())
     {
         newThread = db.AddNewThread(thread, User.Identity.Name);
     }
     //Add Imgaes of Discussion to server
     try
     {
         foreach (HttpPostedFileBase img in Images)
         {
             //rebuild imgae name
             string imageName = WsConstant.randomString() + Path.GetExtension(img.FileName).ToLower();
             string path      = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), imageName);
             img.SaveAs(path);
             string imgaeUrl = "/Content/Upload/" + imageName;
             //Add Image to db.
             using (var db = new AlbumImageDAL())
             {
                 db.AddNewAlbum(new ThreadAlbumImageDTO(newThread.ThreadId, imgaeUrl));
             }
         }
     }
     catch (Exception)
     {
         return(Redirect("/#/Error"));
     }
     return(Redirect("/#/ThreadDetail/" + newThread.ThreadId));
 }
Beispiel #2
0
        public ActionResult UpdateUserAvatar(HttpPostedFileBase Image)
        {
            try
            {
                string ImageName = WsConstant.randomString() + Path.GetExtension(Image.FileName).ToLower();
                string path      = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), ImageName);
                Image.SaveAs(path);
                string newName = "/Content/Upload/" + ImageName;
                //Delete Current Image in Upload folder.

                //Update Current Image to UserInformation
                using (var db = new UserDAL())
                {
                    var userId   = db.GetUserByUserNameOrEmail(User.Identity.Name).UserID;
                    var userInfo = db.GetUserInformation(userId);
                    userInfo.ProfileImage = newName;
                    using (var context = new Ws_DataContext())
                    {
                        context.User_Information.AddOrUpdate(userInfo);
                        context.SaveChanges();
                    }
                    return(Redirect("/#/Profile/" + User.Identity.Name));
                }
            }
            catch (Exception)
            {
                return(Redirect("/#/Error"));
            }
        }
        public ActionResult CreateEvent(CreateEventInfo eventInfo, IEnumerable <HttpPostedFileBase> FileUpload)
        {
            //Get Event Time Lines
            string[] FromDate    = Request.Form.GetValues("FromDate");
            string[] ToDate      = Request.Form.GetValues("ToDate");
            string[] Description = Request.Form.GetValues("Description");
            List <CreateEventSchedule> eventTimeLine = new List <CreateEventSchedule>();

            if (FromDate != null && FromDate.Length >= 1)
            {
                for (int i = 0; i < FromDate.Length; i++)
                {
                    if (FromDate[i] != "" && ToDate[i] != "" && Description[i] != "")
                    {
                        eventTimeLine.Add(new CreateEventSchedule(FromDate[i], ToDate[i], Description[i]));
                    }
                }
            }
            Event newEvent = new Event();

            using (var db = new EventDAL())
            {
                newEvent = db.AddNewEvent(eventInfo, User.Identity.Name);
                foreach (var scheduleInfo in eventTimeLine)
                {
                    db.AddNewEventTimeLine(scheduleInfo, newEvent.EventID);
                }
            }
            //Add Image to server
            try
            {
                foreach (HttpPostedFileBase img in FileUpload)
                {
                    //rebuild image name
                    string imageName = WsConstant.randomString() + Path.GetExtension(img.FileName).ToLower();
                    string path      = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), imageName);
                    img.SaveAs(path);
                    string imgaeUrl = "/Content/Upload/" + imageName;
                    //Add Image to db.
                    using (var db = new AlbumImageDAL())
                    {
                        db.AddEventAlbum(new EventAlbumImageDTO(newEvent.EventID, imgaeUrl));
                    }
                }
            }
            catch (Exception)
            {
                return(Redirect("/#/Error"));
            }
            return(Redirect("/#/EventDetail/" + newEvent.EventID));
        }
Beispiel #4
0
        public ActionResult CreateOrganization(CreateOrganization organization, HttpPostedFileBase LogoImage)
        {
            //Models.Organization newOrganization;
            try
            {
                string logoName = WsConstant.randomString() + Path.GetExtension(LogoImage.FileName).ToLower();
                string path     = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), logoName);
                LogoImage.SaveAs(path);
                organization.LogoUrl = "/Content/Upload/" + logoName;

                using (var db = new OrganizationDAL())
                {
                    db.AddNewOrganization(organization, User.Identity.Name);
                }
            }
            catch (Exception)
            {
                return(Redirect("/#/Error"));
            }

            return(Redirect("/#/Home"));
        }
Beispiel #5
0
        public ActionResult EditOrganization(CreateOrganization organization, HttpPostedFileBase LogoImage)
        {
            try
            {
                Organization organi = new Organization();
                if (LogoImage != null)
                {
                    string logoName = WsConstant.randomString() + Path.GetExtension(LogoImage.FileName).ToLower();
                    string path     = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), logoName);
                    LogoImage.SaveAs(path);
                    organization.LogoUrl = "/Content/Upload/" + logoName;
                }

                using (var db = new OrganizationDAL())
                {
                    organi = db.EditOrganization(organization, User.Identity.Name);
                }
                return(Redirect("/#/OrganizationDetail/" + organi.OrganizationId));
            }
            catch (Exception)
            {
                return(Redirect("/#/Error"));
            }
        }