コード例 #1
0
        public async Task <IActionResult> SaveEvent(SaveEventVM data, IFormFile slika)
        {
            if (slika != null && slika.Length > 0)
            {
                var nazivFajla = Path.GetFileName(slika.FileName);
                var putanja    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\items", nazivFajla);
                using (var fajlSteam = new FileStream(putanja, FileMode.Create))
                {
                    await slika.CopyToAsync(fajlSteam);
                }

                data.Image = nazivFajla;

                int optRadio = Int32.Parse(data.OptRadio);
                int optCombo = Int32.Parse(data.OptCombo);
                var newEvent = new EventInsertRequest()
                {
                    Name          = data.Name,
                    Description   = data.Description,
                    Image         = data.Image,
                    Start         = data.Start,
                    End           = data.End,
                    EventCategory = (EventCategory)(optRadio),
                    VenueID       = optCombo,
                    IsApproved    = false,
                    IsCanceled    = false,
                    OrganizerID   = data.OrganizerID
                };

                await _eventiApi.CreateEventAsync(newEvent);
            }
            return(Redirect("Index"));
        }
コード例 #2
0
ファイル: EventController.cs プロジェクト: EnisMulic/Eventi
        public async Task <IActionResult> EventSave(EventVM model, IFormFile image)
        {
            String fileName = new String("");

            if (image != null && image.Length > 0)
            {
                fileName = Path.GetFileName(image.FileName);
                //var mappedPath = HttpContext.GetServerVariable.MapPath("~/Content/Images/");
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\items", fileName);
                using (var fajlSteam = new FileStream(path, FileMode.Create))
                {
                    await image.CopyToAsync(fajlSteam);
                }
            }

            if (model.ID == 0)
            {
                var insertRequest = new EventInsertRequest()
                {
                    Name          = model.Name,
                    Description   = model.Description,
                    EventCategory = model.EventCategory,
                    Start         = model.Start,
                    End           = model.Start,
                    IsApproved    = model.IsApproved,
                    IsCanceled    = model.IsCanceled,
                    OrganizerID   = model.OrganizerID,
                    VenueID       = model.VenueID,
                    Image         = fileName
                };

                await _eventiApi.CreateEventAsync(insertRequest);
            }
            else
            {
                var updateRequest = new EventUpdateRequest()
                {
                    Name            = model.Name,
                    Description     = model.Description,
                    EventCategory   = model.EventCategory,
                    Start           = model.Start,
                    End             = model.Start,
                    IsApproved      = model.IsApproved,
                    IsCanceled      = model.IsCanceled,
                    OrganizerID     = model.OrganizerID,
                    AdministratorID = model.AdministratorID,
                    VenueID         = model.VenueID,
                    Image           = fileName
                };

                await _eventiApi.UpdateEventAsync(model.ID, updateRequest);
            }

            return(Redirect("Index"));
        }