コード例 #1
0
        public ActionResult EditCategory(UserCategoryModel Model)
        {
            try
            {
                tblUserCategory TCtable = Connection.tblUserCategories.SingleOrDefault(
                    x => x.CategoryId == Model.CategoryId);

                if (Model.Active == true)
                {
                    TCtable.IsActive = "Y";
                }
                else
                {
                    TCtable.IsActive = "N";
                }
                TCtable.CategoryName = Model.CategoryName;
                TCtable.ModifiedDate = DateTime.Now;
                TCtable.ModifiedBy   = "ADMIN";
                Connection.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #2
0
        public static MobsError Update(UserCategoryModel model)
        {
            var context = "UserCategoryProvider.Update";

            try
            {
                using (var db = new dbMobs())
                {
                    if (db.UserCategories.Any(e => e.Name == model.Name && e.Id != model.Id && e.UserId == model.UserId))
                    {
                        return(new MobsError(context, MobsErrorEnum.DuplicateCategory));
                    }

                    var dbe = db.UserCategories.Find(model.Id);
                    if (dbe == null)
                    {
                        return(new MobsError(context, MobsErrorEnum.DataNotFound));
                    }

                    dbe.Name = model.Name;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                new MobsError(context, e);
            }
            return(null);
        }
コード例 #3
0
        public static MobsError Create(UserCategoryModel model)
        {
            var context = "UserCategoryProvider.Create";

            try
            {
                using (var db = new dbMobs())
                {
                    if (db.UserCategories.Any(e => e.Name == model.Name && e.UserId == model.UserId))
                    {
                        return(new MobsError(context, MobsErrorEnum.EmailAddressInUse));
                    }
                    var dbe = new UserCategory
                    {
                        Name = model.Name, UserId = model.UserId,
                    };
                    db.UserCategories.Add(dbe);
                    db.SaveChanges();
                    model.Id = dbe.Id;
                }
            }
            catch (Exception e)
            {
                new MobsError(context, e);
            }
            return(null);
        }
コード例 #4
0
        public ActionResult CreateCategory(UserCategoryModel Model)
        {
            try
            {
                tblUserCategory Category = new tblUserCategory();

                Category.CreatedBy   = "ADMIN";
                Category.CreatedDate = DateTime.Now;

                if (Model.Active == true)
                {
                    Category.IsActive = "Y";
                }
                else
                {
                    Category.IsActive = "N";
                }

                if (Model.IsApplicationSide == true)
                {
                    Category.IsApplicationSide = "Y";
                }
                else
                {
                    Category.IsApplicationSide = "N";
                }

                Category.CategoryId   = Model.CategoryId;
                Category.CategoryName = Model.CategoryName;

                Connection.tblUserCategories.Add(Category);
                Connection.SaveChanges();

                return(RedirectToAction("Category"));
            }
            catch (Exception Ex)
            {
                Errorlog.ErrorManager.LogError("CreateCategory(UserCategoryModel Model) @ UserController", Ex);
                return(RedirectToAction("Category"));
            }
        }
コード例 #5
0
        public ActionResult EditCategory(string CategoryId)
        {
            UserCategoryModel TModel = new UserCategoryModel();

            tblUserCategory TCtable = Connection.tblUserCategories.SingleOrDefault(
                x => x.CategoryId == CategoryId);

            TModel.IsActive = TCtable.IsActive;
            if (TCtable.IsActive.Equals("Y"))
            {
                TModel.Active = true;
            }
            else
            {
                TModel.Active = false;
            }
            TModel.CategoryName = TCtable.CategoryName;
            TModel.CategoryId   = TCtable.CategoryId;

            return(PartialView("EditCategory", TModel));
        }
コード例 #6
0
        public async Task <HttpResponseMessage> PostCategories([FromBody] UserCategoryModel model)
        {
            try
            {
                var response = await Task.Run(() =>
                {
                    var user = DataContext.AspNetUsers.Find(model.UserId);

                    if (user == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, String.Format("That user does not exist: {0}", model.UserId)));
                    }

                    var categories = new List <Data.Category>();
                    if (model.MyCategories != null)
                    {
                        foreach (CategoryModel categoryModel in model.MyCategories)
                        {
                            var category = DataContext.Categories.SingleOrDefault(c => c.Id == categoryModel.Id);
                            if (category != null)
                            {
                                categories.Add(category);
                            }
                        }
                    }

                    user.Categories.Clear();
                    categories.ForEach(x => user.Categories.Add(x));
                    DataContext.Commit();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                });

                return(response);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }