public ActionResult Products_Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)
 {
     // Will keep the inserted entitites here. Used to return the result later.
     var entities = new List<Product>();
     if (ModelState.IsValid)
     {
         using (var northwind = new NorthwindEntities())
         {
             foreach (var product in products)
             {
                 // Create a new Product entity and set its properties from the posted ProductViewModel
                 var entity = new Product
                 {
                     ProductName = product.ProductName,
                     UnitsInStock = product.UnitsInStock
                 };
                 // Add the entity
                 northwind.Products.Add(entity);
                 // Store the entity for later use
                 entities.Add(entity);
             }
             // Insert the entities in the database
             northwind.SaveChanges();
         }
     }
     // Return the inserted entities. The grid needs the generated ProductID. Also return any validation errors.
     return Json(entities.ToDataSourceResult(request, ModelState, product => new ProductViewModel
     {
         ProductID = product.ProductID,
         ProductName = product.ProductName,
         UnitsInStock = product.UnitsInStock
     }));
 }
Example #2
0
        public ActionResult FDP_Create([DataSourceRequest] DataSourceRequest request, FDPViewModel fdpViewModel , int? adminUnitID)
        {
            var result = new List<FDPViewModel>();

            if (fdpViewModel != null && ModelState.IsValid && adminUnitID.HasValue)
            {
                try
                {
                    //foreach (var viewModel in fdpViewModel)
                    //{

                    if (CheckIfDFPExists((int)adminUnitID, fdpViewModel.Name))
                        {
                            fdpViewModel.AdminUnitID = adminUnitID.Value;
                            var fdp = FDPViewModelBinder.BindFDP(fdpViewModel);
                            _fdpService.AddFDP(fdp);
                            //result.Add(fdpViewModel);
                        }
                   // }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Errors", @"Error: FDP not registered. All fields need to be filled.");
                }
            }
            return Json(result.ToDataSourceResult(request, ModelState));
        }
        public ActionResult CreatePet([DataSourceRequest]DataSourceRequest request, IEnumerable<AdministrationPetsViewModel> models)
        {
            var result = new List<AdministrationPetsViewModel>();
            if (this.ModelState.IsValid && models != null)
            {
                foreach (var model in models)
                {
                    var owner = this.users.GetByUsername(model.Owner).FirstOrDefault();
                    var breed = this.breeds.GetById(model.BreedId).FirstOrDefault();
                    var location = this.locations.GetById(model.LocationId).FirstOrDefault();
                    var status = this.petStatuses.GetById(model.PetStatusId).FirstOrDefault();
                    if (owner != null && breed != null && location != null && status != null)
                    {
                        var newPet = new Pet { Name = model.Name, Description = model.Description, Breed = breed, Owner = owner, Location = location, PetStatus = status, ImageUrl = model.ImageUrl, PetGender = model.PetGenderType };
                        this.pets.Add(newPet);
                        model.CreatedOn = newPet.CreatedOn;
                        model.Id = newPet.Id;
                        result.Add(model);
                    }
                }

                return this.Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }

            return null;
        }
 public JsonResult List_Read(DataSourceRequest request)
 {
     var items = _activityBusinessLogic.GetAllEntities().ToArray();//.Select(x => new ActivityModel
     //{
     //    Id = x.Id,
     //    ActivityDate = x.CreateDate,
     //    UserName = x.Author.Name,
     //    Type = x.Type.Name,
     //    UserAgent = x.UserAgent,
     //    //Tags = x.GetAllTags(),
     //}).ToList();
     items.FirstOrDefault();
     var act = new List<ActivityModel>();
     foreach (var activity in items)
     {
         act.Add(new ActivityModel
         {
             Tags = activity.GetAllTags(),
             Id = activity.Id,
             UserAgent = activity.UserAgent,
             ActivityDate = activity.CreateDate,
             UserName = activity.Author.Name,
             //Type = activity.Type.Name
         });
     }
     DataSourceResult result = act.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
        public ActionResult Section_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Section> sections)
        {
            var results = new List<Section>();

            if (sections != null && ModelState.IsValid)
            {
                foreach (var section in sections)
                {
                    var addedSection = sectionDataHandler.AddSection(section);
                    if (addedSection != null)
                    {
                        ViewBag.Message = "Record saved";
                        ViewBag.ErrorFound = false;

                        section.SectionID = addedSection.SectionID;
                    }
                    else
                    {
                        ViewBag.Message = "Failed to save record";
                        ViewBag.ErrorFound = true;

                    }

                    results.Add(section);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult CreateRating([DataSourceRequest]DataSourceRequest request, IEnumerable<AdministrationRatingsViewModel> models)
        {
            var result = new List<AdministrationRatingsViewModel>();
            if (this.ModelState.IsValid && models != null)
            {
                foreach (var model in models)
                {
                    var ratingUser = this.users.GetByUsername(model.UserName).FirstOrDefault();
                    var petToUpdate = this.pets.GetByIntId(model.PetId).FirstOrDefault();
                    if (ratingUser != null && petToUpdate != null)
                    {
                        var newRating = new Rating { RatingValue = model.RatingValue, PetId = model.PetId, Author = ratingUser };
                        this.ratings.Add(newRating);
                        petToUpdate.CurrentRating = petToUpdate.Ratings.Average(r => r.RatingValue);
                        this.pets.Update(petToUpdate);
                        model.CreatedOn = newRating.CreatedOn;
                        model.Id = newRating.Id;
                        result.Add(model);
                    }
                }

                return this.Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }

            return null;
        }
        public ActionResult Pie_Read([DataSourceRequest] DataSourceRequest request)
        {
            var Dessert = db.Dessert.Where(x => x.DessertKind == "Pie" && x.IsOnSale);
            List<AddDessertViewModel> PieDessert = new List<AddDessertViewModel>();
                foreach (var item in Dessert)
                {
                    PieDessert.Add(AddModel(item));
                }

            return Json(PieDessert.ToDataSourceResult(request));
        }
Example #8
0
 public JsonResult GetCompanies(DataSourceRequest request)
 {
     var items = _companyBusinessLogic.GetAllEntities().ToList();
     var models = new List<CompanyModel>();
     foreach (var company in items)
     {
         models.Add(company.ConvertToCompanyModel());
     }
     var result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
Example #9
0
 public JsonResult List_Read(DataSourceRequest request, Guid id)
 {
     var items = _siteBusinessLogic.GetAllEntities().Where(x => x.Owner.Id == id);//.Select(x => ConvertToSiteModel(x));
     var models = new List<SiteModel>();
     foreach (var clientSite in items)
     {
         models.Add(clientSite.ConvertToSiteModel());
     }
     DataSourceResult result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
Example #10
0
 public JsonResult GetCompanySites(DataSourceRequest request, Guid id)
 {
     var items = _companyBusinessLogic.GetAllEntities().Where(x => x.Id == id).SelectMany(x => x.Sites).ToList();
     var models = new List<SiteModel>();
     foreach (var site in items)
     {
         models.Add(site.ConvertToSiteModel());
     }
     var result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
Example #11
0
 public JsonResult List_Read(DataSourceRequest request)
 {
     var items = _leadTypeBusinessLogic.GetAllEntities();//.Select(x => ConvertToSiteModel(x));
     var models = new List<LeadTypeModel>();
     foreach (var clientSite in items)
     {
         //models.Add(ConvertToLeadModel(clientSite));
     }
     DataSourceResult result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
 public async Task<JsonResult> Log_Read([DataSourceRequest]DataSourceRequest request, string userID = "")
 {
     List<SlotTransactionModel> allSlotTransaction = new List<SlotTransactionModel>();
     if (string.IsNullOrWhiteSpace(userID))
     {
        
         using (var client = new HttpClient())
         {
             string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
             client.BaseAddress = new Uri(url);
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = await client.GetAsync("api/SlotTransaction/GetSlotTransaction");
             if (response.IsSuccessStatusCode)
             {
                 allSlotTransaction = await response.Content.ReadAsAsync<List<SlotTransactionModel>>();
             }
         }
         DataSourceResult result = allSlotTransaction.ToDataSourceResult(request);
         return Json(result);
     }
     else
     {
         int UserID = int.Parse(userID);                 
         using (var client = new HttpClient())
         {
             string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
             client.BaseAddress = new Uri(url);
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = await client.GetAsync("api/SlotTransaction/GetSlotTransactionAsUser?userId=" + UserID);
             if (response.IsSuccessStatusCode)
             {
                 allSlotTransaction = await response.Content.ReadAsAsync<List<SlotTransactionModel>>();
             }
         }
         DataSourceResult result = allSlotTransaction.ToDataSourceResult(request);
         return Json(result);
     }
     
 }
        public ActionResult CreateRate([DataSourceRequest] DataSourceRequest request,
            [Bind(Prefix = "models")]IEnumerable<ProviderRate> products)
        {
            var results = new List<ProviderRate>();

            if (products != null && ModelState.IsValid)
            {
                results.AddRange(products);
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
        {
            var results = new List<ProductViewModel>();

            if (product != null && ModelState.IsValid)
            {
                SessionProductRepository.Insert(product);
                results.Add(product);
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
 public ActionResult Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<LessonTypeGrid> lessons)
 {
     var results = new List<LessonTypeGrid>();
     if (lessons != null)
     {
         foreach (var lesson in lessons)
         {
             store.Create(lesson);
             results.Add(lesson);
         }
     }
     return Json(results.ToDataSourceResult(request));
 }
Example #16
0
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ArticleCate> ArticleCates)
        {
            var results = new List<ArticleCate>();

            if (ArticleCates != null && ModelState.IsValid)
            {
                foreach (var ArticleCate in ArticleCates)
                {
                    ArticleCateService.Create(ArticleCate);
                }
            }
            return Json(results.ToDataSourceResult(request, ModelState));
        }
Example #17
0
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Area> areas)
        {
            var results = new List<Area>();

            if (areas != null && ModelState.IsValid)
            {
                foreach (var area in areas)
                {
                    areaService.Create(area);
                }
            }
            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Member_CreditIndex_Type> Member_CreditIndex_Types)
        {
            var results = new List<Member_CreditIndex_Type>();

            if (Member_CreditIndex_Types != null && ModelState.IsValid)
            {
                foreach (var Member_CreditIndex_Type in Member_CreditIndex_Types)
                {
                    Member_CreditIndex_TypeService.Create(Member_CreditIndex_Type);
                }
            }
            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<CompanyBussiness> CompanyBussinesss)
        {
            var results = new List<CompanyBussiness>();

            if (CompanyBussinesss != null && ModelState.IsValid)
            {
                foreach (var CompanyBussiness in CompanyBussinesss)
                {
                    CompanyBussinessService.Create(CompanyBussiness);
                }
            }
            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, Tweet tweet)
        {
            var results = new List<Tweet>();

            if (ModelState.IsValid)
            {
                this.Data.Tweets.Add(tweet);
                this.Data.SaveChanges();
                results.Add(tweet);
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
        protected ActionResult BaseCreate([DataSourceRequest]DataSourceRequest request, object model)
        {
            var list = new List<object>();

            if (model != null && ModelState.IsValid)
            {
                var itemForAdding = this.Data.Context.Entry(model);
                itemForAdding.State = EntityState.Added;
                this.Data.SaveChanges();
                list.Add(model);
            }

            return this.Json(list.ToDataSourceResult(request));
        }
        public ActionResult Update([DataSourceRequest]DataSourceRequest request, ModelType model)
        {
            var list = new List<ModelType>();

            if (model != null && ModelState.IsValid)
            {
                var itemForUpdating = this.Data.Context.Entry(model.ToEntity);
                itemForUpdating.State = EntityState.Modified;
                this.Data.SaveChanges();
                list.Add(model);
            }

            return this.Json(list.ToDataSourceResult(request));
        }
Example #23
0
        public JsonResult List_Read(DataSourceRequest request)
        {
            var items = _contactBusinessLogic.GetAllEntities().ToList();//.Select(x => x.ConvertToContactModel());

            var models = new List<ContactModel>();

            foreach (var contact in items)
            {
                models.Add(contact.ConvertToContactModel());
            }

            DataSourceResult result = models.ToDataSourceResult(request);
            return Json(result);
        }
Example #24
0
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, CategoryViewModel cat)
        {
            var results = new List<CategoryViewModel>();

            if (cat != null && ModelState.IsValid)
            {

                _repository.Create(cat);
                cat.ID = _repository.Categories.First().ID;
                results.Add(cat);
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)
        {
            var results = new List<ProductViewModel>();

            if (products != null && ModelState.IsValid)
            {
                foreach (var product in products)
                {
                    SessionProductRepository.Insert(product);
                    results.Add(product);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public JsonResult Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<License> licenses)
        {
            var results = new List<License>();

            if (licenses != null && ModelState.IsValid)
            {
                foreach (var license in licenses)
                {
                    LicenseRepository.Repository.Insert(license);
                    results.Add(license);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
Example #27
0
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Permissions> permissions)
        {
            var results = new List<Permissions>();

            if (permissions != null && ModelState.IsValid)
            {
                foreach (var permission in permissions)
                {
                    permissionService.Create(permission);
                    results.Add(permission);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
        public ActionResult ForeignKeyColumn_Create([DataSourceRequest] DataSourceRequest request, 
            [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)
        {
            var results = new List<ProductViewModel>();
            if (products != null && ModelState.IsValid)
            {
                foreach (var product in products)
                {
                    productService.Create(product);
                    results.Add(product);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
Example #29
0
        public ActionResult StockCreate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Stock> products)
        {
            var results = new List<Stock>();

            if (products != null && ModelState.IsValid)
            {
                foreach (var product in products)
                {
                    service.Create(product);
                    results.Add(product);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
Example #30
0
        public ActionResult Update([DataSourceRequest]DataSourceRequest request, ViewModelType model)
        {
            var list = new List<ViewModelType>();

            if (model != null && this.ModelState.IsValid)
            {
                var userProfile = this.Data.Users.All().FirstOrDefault(u => u.Id == model.Id);
                var itemForUpdating = this.Data.Context.Entry(model.GetEntityModel(userProfile));
                itemForUpdating.State = EntityState.Modified;
                this.Data.SaveChanges();
                list.Add(model);
            }

            return this.Json(list.ToDataSourceResult(request));
        }