Пример #1
0
        // List<Ticket> ticket1 = new List<Ticket>();


        public static async Task SeedAsync(EventCatalogContext context)
        {
            context.Database.Migrate();
            if (!context.Places.Any())
            {
                context.Places.AddRange
                    (GetPreconfiguredPlaces());
                await context.SaveChangesAsync();
            }
            if (!context.Tickets.Any())
            {
                context.Tickets.AddRange
                    (GetPreconfiguredTickets());
                context.SaveChanges();
            }
            if (!context.Users.Any())
            {
                context.Users.AddRange
                    (GetPreconfiguredUsers());
                context.SaveChanges();
            }
            if (!context.Eventcatalogs.Any())
            {
                context.Eventcatalogs.AddRange
                    (GetPreconfiguredevent());
                context.SaveChanges();
            }
        }
        public static void Seed(EventCatalogContext EventCatalogContext, IWebHostEnvironment env)
        {
            EventCatalogContext.Database.Migrate();

            if (!EventCatalogContext.EventAudiences.Any())
            {
                EventCatalogContext.EventAudiences.AddRange(GetEventAudiences());
                EventCatalogContext.SaveChanges();
            }

            if (!EventCatalogContext.EventCategories.Any())
            {
                EventCatalogContext.EventCategories.AddRange(GetEventCategories());
                EventCatalogContext.SaveChanges();
            }
            if (!EventCatalogContext.EventKinds.Any())
            {
                EventCatalogContext.EventKinds.AddRange(GetEventKinds());
                EventCatalogContext.SaveChanges();
            }

            if (!EventCatalogContext.EventLanguages.Any())
            {
                EventCatalogContext.EventLanguages.AddRange(GetEventLanguages());
                EventCatalogContext.SaveChanges();
            }

            if (!EventCatalogContext.EventFormats.Any())
            {
                EventCatalogContext.EventFormats.AddRange(GetEventFormats());
                EventCatalogContext.SaveChanges();
            }

            if (!EventCatalogContext.EventLocations.Any())
            {
                EventCatalogContext.EventLocations.AddRange(GetEventLocations());
                EventCatalogContext.SaveChanges();
            }


            if (!EventCatalogContext.EventZipCodes.Any())
            {
                EventCatalogContext.EventZipCodes.AddRange(GetEventZipCodes());
                EventCatalogContext.SaveChanges();
            }
        }
        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);
            }
        }
Пример #4
0
        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);
            }
        }