コード例 #1
0
        public void MapAndUnmapPhotographyCategory(long id)
        {
            var allMappings    = _databaseConnection.PhotographerCategoryMappings.ToList();
            var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId"));
            var userMapping    =
                allMappings.SingleOrDefault(n => n.AppUserId == signedInUserId && n.PhotographerCategoryId == id);

            if (userMapping != null)
            {
                _databaseConnection.PhotographerCategoryMappings.Remove(userMapping);
                _databaseConnection.SaveChanges();
            }
            else
            {
                var categoryMapping = new PhotographerCategoryMapping
                {
                    PhotographerCategoryId = id,
                    AppUserId        = signedInUserId,
                    DateCreated      = DateTime.Now,
                    DateLastModified = DateTime.Now,
                    LastModifiedBy   = signedInUserId,
                    CreatedBy        = signedInUserId
                };
                _databaseConnection.PhotographerCategoryMappings.Add(categoryMapping);
                _databaseConnection.SaveChanges();
            }
            //var categories = _databaseConnection.PhotographerCategories.ToList();
            //ViewBag.Mapping = _databaseConnection.PhotographerCategoryMappings.ToList();
            //return PartialView("Partials/_PartialPhotoCategory",categories);
        }
コード例 #2
0
        public ActionResult MapPhotographyCategory(int[] table_records, IFormCollection collection)
        {
            var allMappings    = _databaseConnection.PhotographerCategoryMappings.ToList();
            var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId"));

            if (table_records != null)
            {
                var length = table_records.Length;
                for (var i = 0; i < length; i++)
                {
                    var id            = table_records[i];
                    var singleMapping = allMappings.SingleOrDefault(
                        n =>
                        n.PhotographerCategoryId == id && n.AppUserId == signedInUserId);
                    if (singleMapping != null)
                    {
                    }
                    else
                    {
                        var categoryMapping = new PhotographerCategoryMapping
                        {
                            PhotographerCategoryId = id,
                            AppUserId        = signedInUserId,
                            DateCreated      = DateTime.Now,
                            DateLastModified = DateTime.Now,
                            LastModifiedBy   = signedInUserId,
                            CreatedBy        = signedInUserId
                        };
                        _databaseConnection.PhotographerCategoryMappings.Add(categoryMapping);
                        _databaseConnection.SaveChanges();
                    }
                }
                TempData["display"]          = "you have succesfully added the category(s) to the profile!";
                TempData["notificationtype"] = NotificationType.Success.ToString();
            }
            else
            {
                TempData["display"]          = "no category has been selected!";
                TempData["notificationtype"] = NotificationType.Error.ToString();
                return(RedirectToAction("SelectCategories", "PhotographerCategory"));
            }
            return(RedirectToAction("SelectCategories", "PhotographerCategory"));
        }