Ejemplo n.º 1
0
        public Event AddNewEvent(CreateEventInfo eventInfo, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newEvent = CreateEmptyEvent();

            newEvent.CreatorID  = GetOrganizationById(CurrenUser).OrganizationId;
            newEvent.EventType  = eventInfo.EventType;
            newEvent.EventName  = eventInfo.EventName;
            newEvent.EEventName = ConvertToUnSign.Convert(newEvent.EventName);
            if (eventInfo.StartDate != "")
            {
                newEvent.Start_Date = DateTime.Parse(eventInfo.StartDate);
            }
            if (eventInfo.FinishDate != "")
            {
                newEvent.Finish_Date = DateTime.Parse(eventInfo.FinishDate);
            }
            newEvent.ShortDescription = eventInfo.ShortDescription;
            newEvent.Location         = eventInfo.Location;
            newEvent.ExpectedMoney    = eventInfo.ExpectedMoney;
            newEvent.Description      = eventInfo.Content;
            newEvent.Contact          = eventInfo.Contact;
            newEvent.VideoUrl         = eventInfo.VideoUrl;
            using (var db = new Ws_DataContext())
            {
                db.Events.Add(newEvent);
                db.SaveChanges();
                return(GetEventById(newEvent.EventID));
            }
        }
Ejemplo n.º 2
0
        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));
        }