Beispiel #1
0
        public async Task <IActionResult> EventDetails([FromForm] EventInputData eventInput, IFormFile File)
        {
            var result = await EventCatalogSeed.UpdateEvent(eventInput, _context, File, _env);

            if (result == "Event Addition Succesful")
            {
                return(Ok(result));
            }
            else
            {
                return(Problem(result));
            }
        }
Beispiel #2
0
        //included
        public async Task <IActionResult> EventDetails([FromForm] string eventInput, IFormFile File)
        {
            var str = eventInput;

            EventInputData eventInput1 = new EventInputData();

            eventInput1 = JsonConvert.DeserializeObject <EventInputData>(eventInput);
            var result = await EventCatalogSeed.UpdateEvent(eventInput1, _context, File, _env);

            if (result == "Event Addition Succesful")
            {
                return(Ok(result));
            }
            else
            {
                return(Problem(result));
            }
        }
        public static async Task <String> UpdateEvent(EventInputData eventInput, EventCatalogContext catalogContext, IFormFile File, IWebHostEnvironment env)
        {
            EventItem eventItem = new EventItem();

            try
            {
                eventItem.Event_Name        = eventInput.Inp_Event_Name;
                eventItem.Event_Desc        = eventInput.Inp_Event_Desc;
                eventItem.Event_Capacity    = eventInput.Inp_Event_Capacity;
                eventItem.Event_Start_Time  = eventInput.Inp_Start_Time;
                eventItem.Event_End_Time    = eventInput.Inp_End_Time;
                eventItem.Event_Price       = eventInput.Inp_Price;
                eventItem.Event_Address     = eventInput.Inp_Address;
                eventItem.Event_Online_Link = eventInput.Inp_Online_Link;

                if (File != null)
                {
                    eventItem.Event_Pictureurl = File.FileName;
                    var result = await upload_file(File, env);

                    if (result != "Ok")
                    {
                        return(result);
                    }
                }
                else
                {
                    eventItem.Event_Pictureurl = "Picture Not Provided";
                }

                int key = 0;


                if (eventInput.Inp_Event_Category != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Category, catalogContext, "Category");

                    eventItem.Event_CategoryId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Category == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Category is null"));
                }


                if (eventInput.Inp_Event_Audience != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Audience, catalogContext, "Audiences");

                    eventItem.Event_AudienceId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Audience == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Audience is null"));
                }


                if (eventInput.Inp_Event_Format != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Format, catalogContext, "Format");

                    eventItem.Event_FormatId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Format == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Format is null"));
                }


                if (eventInput.Inp_Event_Kind != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Kind, catalogContext, "Kind");

                    eventItem.Event_KindId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Kind == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Kind is null"));
                }

                if (eventInput.Inp_Event_Location != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Location, catalogContext, "Location");

                    eventItem.Event_LocationId = key;
                }

                if (key == 0 || eventInput.Inp_Event_Location == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Location is null"));
                }


                if (eventInput.Inp_Event_Language != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Language, catalogContext, "Language");

                    eventItem.Event_LanguageId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Language == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Language is null"));
                }

                if (eventInput.Inp_Event_ZipCode != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_ZipCode, catalogContext, "ZipCode");

                    eventItem.Event_ZipCodeId = key;
                }

                if (key == 0 || eventInput.Inp_Event_ZipCode == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_ZipCode is null"));
                }

                if (eventInput.Inp_Event_User != null)
                {
                    var user = catalogContext.EventUserInfos
                               .Where(b => b.UserName == eventInput.Inp_Event_User)
                               .FirstOrDefault();
                    if (user == null)
                    {
                        throw new ArgumentNullException(String.Format("Inp_Event_user not found"));
                    }
                    eventItem.Event_UserId = user.UserName;
                }
                if (eventItem.Event_UserId == null || eventInput.Inp_Event_User == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_user is null"));
                }



                await catalogContext.EventItems.AddAsync(eventItem);

                catalogContext.SaveChanges();

                return("Event Addition Succesful");
            }

            catch (ArgumentNullException ex)
            {
                return(ex.GetType().Name + ex.Message);
            }
        }
        public static async Task <String> UpdateEvent(EventInputData eventInput, EventCatalogContext catalogContext, IFormFile File, IWebHostEnvironment env)
        {
            EventItem eventItem = new EventItem();

            try
            {
                eventItem.Event_Name       = eventInput.Inp_Event_Name;
                eventItem.Event_Desc       = eventInput.Inp_Event_Desc;
                eventItem.Event_Organiser  = eventInput.Inp_Event_Organiser;
                eventItem.Event_Start_Time = eventInput.Inp_Start_Time;
                eventItem.Event_End_Time   = eventInput.Inp_End_Time;
                eventItem.Event_Price      = eventInput.Inp_Price;

                if (File != null)
                {
                    eventItem.Event_Pictureurl = File.FileName;
                    var result = await upload_file(File, env);

                    if (result != "Ok")
                    {
                        return(result);
                    }
                }
                else
                {
                    eventItem.Event_Pictureurl = "Picture Not Provided";
                }

                int key = 0;


                if (eventInput.Inp_Event_Category != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Category, catalogContext, "Category");

                    eventItem.Event_CategoryId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Category == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Category is null"));
                }


                if (eventInput.Inp_Event_Audience != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Audience, catalogContext, "Audiences");

                    eventItem.Event_AudienceId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Audience == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Audience is null"));
                }


                if (eventInput.Inp_Event_Format != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Format, catalogContext, "Format");

                    eventItem.Event_FormatId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Format == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Format is null"));
                }


                if (eventInput.Inp_Event_Kind != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Kind, catalogContext, "Kind");

                    eventItem.Event_KindId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Kind == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Kind is null"));
                }

                if (eventInput.Inp_Event_Location != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Location, catalogContext, "Location");

                    eventItem.Event_LocationId = key;
                }

                if (key == 0 || eventInput.Inp_Event_Location == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Location is null"));
                }


                if (eventInput.Inp_Event_Language != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_Language, catalogContext, "Language");

                    eventItem.Event_LanguageId = key;
                }
                if (key == 0 || eventInput.Inp_Event_Language == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_Language is null"));
                }

                if (eventInput.Inp_Event_ZipCode != null)
                {
                    key = await FindForeignKey(eventInput.Inp_Event_ZipCode, catalogContext, "ZipCode");

                    eventItem.Event_ZipCodeId = key;
                }

                if (key == 0 || eventInput.Inp_Event_ZipCode == null)
                {
                    throw new ArgumentNullException(String.Format("Inp_Event_ZipCode is null"));
                }



                try
                {
                    await catalogContext.EventItems.AddAsync(eventItem);

                    catalogContext.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    return("DB UPDATE FAILED");
                }

                return("Event Addition Succesful");
            }

            catch (ArgumentNullException ex)
            {
                return(ex.GetType().Name + ex.Message);
            }
        }