コード例 #1
0
 public ActionResult Create(string Tab)
 {
     ValueList valueList = GStoreDb.ValueLists.Create();
     valueList.SetDefaultsForNew(CurrentClientOrThrow);
     ValueListEditAdminViewModel viewModel = new ValueListEditAdminViewModel(CurrentStoreFrontOrThrow, CurrentUserProfileOrThrow, valueList, Tab, isStoreAdminEdit: true, isCreatePage: true);
     return View("Create", viewModel);
 }
コード例 #2
0
		public ValueListItemEditAdminViewModel(ValueListEditAdminViewModel valueListViewModel, ValueListItem valueListItem, int index)
		{
			if (valueListViewModel == null)
			{
				throw new ArgumentNullException("valueListViewModel");
			}

			if (valueListViewModel.ValueList == null)
			{
				throw new ArgumentNullException("valueListViewModel.ValueList", "valueListViewModel.ValueList cannot be null. make sure edit page sets this after post");
			}

			this.Index = index;

			this.ValueListEditAdminViewModel = valueListViewModel;
			this.ValueList = valueListViewModel.ValueList;
			this.ValueListId = valueListViewModel.ValueList.ValueListId;

			this.IsStoreAdminEdit = valueListViewModel.IsStoreAdminEdit;
			this.IsReadOnly = valueListViewModel.IsReadOnly;
			this.IsDeletePage = valueListViewModel.IsDeletePage;
			this.IsCreatePage = valueListViewModel.IsCreatePage;
			this.ActiveTab = valueListViewModel.ActiveTab;

			FillListsIfEmpty(valueListItem.Client);

			if (valueListItem == null)
			{
				SetDefaults(valueListViewModel);
			}
			else
			if (valueListItem != null)
			{
				this.Name = valueListItem.Name;
				this.Order = valueListItem.Order;
				this.Description = valueListItem.Description;
				this.IsInteger = valueListItem.IsInteger;
				this.IntegerValue = valueListItem.IntegerValue;
				this.IsString = valueListItem.IsString;
				this.StringValue = valueListItem.StringValue;
				this.ValueListItemId = valueListItem.ValueListItemId;

				this.IsPending = valueListItem.IsPending;
				this.StartDateTimeUtc = valueListItem.StartDateTimeUtc;
				this.EndDateTimeUtc = valueListItem.EndDateTimeUtc;
				this.IsActiveDirect = valueListItem.IsActiveDirect();
				this.IsActiveBubble = valueListItem.IsActiveBubble();
			}
		}
コード例 #3
0
        public ValueListItemEditAdminViewModel(ValueListEditAdminViewModel valueListViewModel, ValueListItem valueListItem, int index)
        {
            if (valueListViewModel == null)
            {
                throw new ArgumentNullException("valueListViewModel");
            }

            if (valueListViewModel.ValueList == null)
            {
                throw new ArgumentNullException("valueListViewModel.ValueList", "valueListViewModel.ValueList cannot be null. make sure edit page sets this after post");
            }

            this.Index = index;

            this.ValueListEditAdminViewModel = valueListViewModel;
            this.ValueList = valueListViewModel.ValueList;
            this.ValueListId = valueListViewModel.ValueList.ValueListId;

            this.IsStoreAdminEdit = valueListViewModel.IsStoreAdminEdit;
            this.IsReadOnly = valueListViewModel.IsReadOnly;
            this.IsDeletePage = valueListViewModel.IsDeletePage;
            this.IsCreatePage = valueListViewModel.IsCreatePage;
            this.ActiveTab = valueListViewModel.ActiveTab;

            FillListsIfEmpty(valueListItem.Client);

            if (valueListItem == null)
            {
                SetDefaults(valueListViewModel);
            }
            else
            if (valueListItem != null)
            {
                this.Name = valueListItem.Name;
                this.Order = valueListItem.Order;
                this.Description = valueListItem.Description;
                this.IsInteger = valueListItem.IsInteger;
                this.IntegerValue = valueListItem.IntegerValue;
                this.IsString = valueListItem.IsString;
                this.StringValue = valueListItem.StringValue;
                this.ValueListItemId = valueListItem.ValueListItemId;

                this.IsPending = valueListItem.IsPending;
                this.StartDateTimeUtc = valueListItem.StartDateTimeUtc;
                this.EndDateTimeUtc = valueListItem.EndDateTimeUtc;
                this.IsActiveDirect = valueListItem.IsActiveDirect();
                this.IsActiveBubble = valueListItem.IsActiveBubble();
            }
        }
コード例 #4
0
		protected void SetDefaults(ValueListEditAdminViewModel valueListViewModel)
		{
			if (valueListViewModel == null)
			{
				return;
			}
			this.Name = "New Item";
			this.Description = "New Item";
			this.Order = (valueListViewModel.ValueListItems.Count == 0 ? 100 : valueListViewModel.ValueListItems.Max(vl => vl.Order) + 10);

			this.IsString = true;
			this.StringValue = "New Item Value";
			this.IsPending = false;
			this.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
			this.StartDateTimeUtc = DateTime.UtcNow.AddYears(100);
		}
コード例 #5
0
        public virtual ActionResult Create(ValueListEditAdminViewModel viewModel)
        {
            Client client = CurrentClientOrThrow;
            bool nameIsValid = GStoreDb.ValidateValueListName(this, viewModel.Name, CurrentClientOrThrow.ClientId, null);

            if (nameIsValid && ModelState.IsValid)
            {
                try
                {
                    ValueList valueList = null;
                    valueList = GStoreDb.CreateValueList(viewModel, CurrentClientOrThrow, CurrentUserProfileOrThrow);
                    AddUserMessage("Value List Created!", "Value List '" + valueList.Name.ToHtml() + "' [" + valueList.ValueListId + "] was created successfully for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]", UserMessageType.Success);
                    if (CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.ValueLists_View))
                    {
                        return RedirectToAction("Details", new { id = valueList.ValueListId });
                    }
                    return RedirectToAction("Index", "StoreAdmin");
                }
                catch (Exception ex)
                {
                    string errorMessage = "An error occurred while Creating Value List '" + viewModel.Name.ToHtml() + "' for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "] \nError: " + ex.GetType().FullName;

                    if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                    {
                        errorMessage += " \nException.ToString(): " + ex.ToString();
                    }
                    AddUserMessage("Error Creating Value List!", errorMessage.ToHtmlLines(), UserMessageType.Danger);
                    ModelState.AddModelError("Ajax", errorMessage);
                }
            }
            else
            {
                AddUserMessage("Value List Create Error", "There was an error with your entry for new Value List '" + viewModel.Name.ToHtml() + "' for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]. Please correct it below and save.", UserMessageType.Danger);
            }
            viewModel.IsStoreAdminEdit = true;
            viewModel.IsCreatePage = true;
            viewModel.IsActiveDirect = !(viewModel.IsPending || (viewModel.StartDateTimeUtc > DateTime.UtcNow) || (viewModel.EndDateTimeUtc < DateTime.UtcNow));

            return View("Create", viewModel);
        }
コード例 #6
0
        protected void SetDefaults(ValueListEditAdminViewModel valueListViewModel)
        {
            if (valueListViewModel == null)
            {
                return;
            }
            this.Name = "New Item";
            this.Description = "New Item";
            this.Order = (valueListViewModel.ValueListItems.Count == 0 ? 100 : valueListViewModel.ValueListItems.Max(vl => vl.Order) + 10);

            this.IsString = true;
            this.StringValue = "New Item Value";
            this.IsPending = false;
            this.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            this.StartDateTimeUtc = DateTime.UtcNow.AddYears(100);
        }
コード例 #7
0
        public ActionResult Delete(int? id, string Tab, string SortBy, bool? SortAscending)
        {
            if (!id.HasValue)
            {
                return HttpBadRequest("ValueListId = null");
            }

            Client client = CurrentClientOrThrow;
            ValueList valueList = client.ValueLists.Where(p => p.ValueListId == id.Value).SingleOrDefault();
            if (valueList == null)
            {
                AddUserMessage("Value List not found", "Sorry, the Value List you are trying to Delete cannot be found. Value List id: [" + id.Value + "] for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]", UserMessageType.Danger);
                return RedirectToAction("Manager");

            }

            ValueListEditAdminViewModel viewModel = new ValueListEditAdminViewModel(CurrentStoreFrontOrThrow, CurrentUserProfileOrThrow, valueList, Tab, true, false, false, sortBy: SortBy, sortAscending: SortAscending);
            return View("Delete", viewModel);
        }
コード例 #8
0
        public virtual PartialViewResult UpdateValueListAjax(int? id, ValueListEditAdminViewModel valueListViewModel, ValueListItemEditAdminViewModel[] listItems, string fastAddValueListItem)
        {
            if (!id.HasValue)
            {
                return HttpBadRequestPartial("id is null");
            }

            if (valueListViewModel.ValueListId == 0)
            {
                return HttpBadRequestPartial("Value List Id in view model is 0");
            }

            if (valueListViewModel.ValueListId != id.Value)
            {
                return HttpBadRequestPartial("Value List Id mismatch. Parameter value: '" + id.Value + "' != view model value: " + valueListViewModel.ValueListId);
            }

            Client client = CurrentClientOrThrow;
            ValueList valueListToUpdate = client.ValueLists.SingleOrDefault(vl => vl.ValueListId == valueListViewModel.ValueListId);

            if (valueListToUpdate == null)
            {
                throw new ApplicationException("Value List not found in client Value Lists. Value List Id: " + valueListToUpdate.ValueListId + " Client '" + client.Name + "' [" + client.ClientId + "]");
            }

            bool nameIsValid = GStoreDb.ValidateValueListName(this, valueListToUpdate.Name, client.ClientId, valueListToUpdate.ValueListId);
            bool fastAddIsValid = false;
            if (!string.IsNullOrWhiteSpace(fastAddValueListItem))
            {
                fastAddIsValid = GStoreDb.ValidateValueListFastAddItemName(this, fastAddValueListItem, valueListToUpdate, null);
            }

            if (nameIsValid && ModelState.IsValid)
            {
                ValueList valueList = null;
                try
                {
                    valueList = GStoreDb.UpdateValueList(valueListViewModel, client, CurrentUserProfileOrThrow);

                    if (listItems != null && listItems.Count() > 0)
                    {
                        foreach (ValueListItemEditAdminViewModel listItem in listItems)
                        {
                            if (listItem.ValueListId != id.Value)
                            {
                                throw new ApplicationException("ValueListId mismatch for list item. ValueList id: " + id.Value + " listItem.ValueListId: " + listItem.ValueListId);
                            }
                            ValueListItem listItemUpdated = GStoreDb.UpdateValueListItem(listItem, client, CurrentUserProfileOrThrow);
                        }
                    }
                    valueListViewModel = new ValueListEditAdminViewModel(CurrentStoreFrontOrThrow, CurrentUserProfileOrThrow, valueList, isStoreAdminEdit: true, activeTab: valueListViewModel.ActiveTab, sortBy: valueListViewModel.SortBy, sortAscending: valueListViewModel.SortAscending);

                    if (fastAddIsValid)
                    {
                        ValueListItem newItem = GStoreDb.CreateValueListItemFastAdd(valueListViewModel, fastAddValueListItem, client, CurrentUserProfileOrThrow);
                        AddUserMessage("Value List Item Created!", "Value List Item '" + newItem.Name.ToHtml() + "' [" + newItem.ValueListItemId + "] created successfully.", UserMessageType.Success);
                        ModelState.Remove("fastAddValueListItem");
                    }

                    AddUserMessage("Value List Changes Saved!", "Value List '" + valueList.Name.ToHtml() + "' [" + valueList.ValueListId + "] saved successfully for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]", UserMessageType.Success);

                    this.ModelState.Clear();
                    return PartialView("_ValueListEditPartial", valueListViewModel);
                }
                catch (Exception ex)
                {
                    string errorMessage = "An error occurred while saving your changes to Value List '" + valueListViewModel.Name + "' [" + valueListViewModel.ValueListId + "] for Client: '" + client.Name + "' [" + client.ClientId + "] \nError: '" + ex.GetType().FullName + "'";

                    if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                    {
                        errorMessage += " \nException.ToString(): '" + ex.ToString() + "'";
                    }
                    AddUserMessage("Error Saving Value List!", errorMessage.ToHtmlLines(), UserMessageType.Danger);
                    ModelState.AddModelError("Ajax", errorMessage);
                }
            }
            else
            {
                AddUserMessage("Value List Edit Error", "There was an error with your entry for Value List " + valueListViewModel.Name.ToHtml() + " [" + valueListViewModel.ValueListId + "] for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]. Please correct it.", UserMessageType.Danger);
            }

            foreach (string key in this.ModelState.Keys.Where(k => k.StartsWith("ValueListItems[")).ToList())
            {
                this.ModelState.Remove(key);
            }

            valueListViewModel.IsStoreAdminEdit = true;
            return PartialView("_ValueListEditPartial", valueListViewModel);
        }
コード例 #9
0
        public static ValueListItem CreateValueListItemFastAdd(this IGstoreDb db, ValueListEditAdminViewModel viewModel, string fastAddName, Client client, UserProfile userProfile)
        {
            if (string.IsNullOrWhiteSpace(fastAddName))
            {
                throw new ArgumentNullException("fastAddName");
            }
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (userProfile == null)
            {
                throw new ArgumentNullException("userProfile");
            }

            ValueListItem newRecord = db.ValueListItems.Create();

            newRecord.Client = client;
            newRecord.ClientId = client.ClientId;
            newRecord.CreateDateTimeUtc = DateTime.UtcNow;
            newRecord.CreatedBy = userProfile;
            newRecord.CreatedBy_UserProfileId = userProfile.UserProfileId;
            newRecord.Description = fastAddName;
            newRecord.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            newRecord.IsPending = false;
            newRecord.Name = fastAddName;
            newRecord.IsInteger = false;
            newRecord.IntegerValue = null;
            newRecord.IsString = true;
            newRecord.StringValue = fastAddName;
            newRecord.Order = (viewModel.ValueListItems == null ? 100 : (viewModel.ValueListItems.Count == 0 ? 100 : (viewModel.ValueListItems.Max(vli => vli.Order) + 100)));
            newRecord.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
            newRecord.ValueList = viewModel.ValueList;
            newRecord.ValueListId = viewModel.ValueListId;
            newRecord.UpdateAuditFields(userProfile);

            newRecord = db.ValueListItems.Add(newRecord);
            db.SaveChanges();

            return newRecord;
        }
コード例 #10
0
        public static ValueList UpdateValueList(this IGstoreDb db, ValueListEditAdminViewModel viewModel, Client client, UserProfile userProfile)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (userProfile == null)
            {
                throw new ArgumentNullException("userProfile");
            }

            //find existing record, update it
            ValueList valueList = client.ValueLists.SingleOrDefault(p => p.ValueListId == viewModel.ValueListId);
            if (valueList == null)
            {
                throw new ApplicationException("Value List not found in client Value Lists. Value List Id: " + viewModel.ValueListId + " Client '" + client.Name + " [" + client.ClientId + "]");
            }

            valueList.Description = viewModel.Description;
            valueList.EndDateTimeUtc = viewModel.EndDateTimeUtc;
            valueList.IsPending = viewModel.IsPending;
            valueList.Name = viewModel.Name;
            valueList.Order = viewModel.Order;
            valueList.StartDateTimeUtc = viewModel.StartDateTimeUtc;
            valueList.UpdateDateTimeUtc = DateTime.UtcNow;
            valueList.UpdatedBy = userProfile;
            valueList.UpdatedBy_UserProfileId = userProfile.UserProfileId;

            valueList.UpdateAuditFields(userProfile);

            valueList = db.ValueLists.Update(valueList);
            db.SaveChanges();

            return valueList;
        }