コード例 #1
0
        /// <summary>
        /// Deletes the specified providers item.
        /// </summary>
        /// <param name="item">The providersitem.</param>
        /// <exception cref="System.ArgumentNullException">item</exception>
        public void Delete(ProvidersItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            this._providersItemsRepository.Delete(item);
        }
コード例 #2
0
        public ActionResult ManageDress(ItemViewModel model)
        {
            //PhiUser currentUser = _userStore.FindByNameAsync(User.Identity.GetUserName()).Result;
            if (ModelState.IsValid)
            {
                try
                {
                    string userId            = User.Identity.GetUserId();
                    var    userItemProviders = this._dataStore.GetItemProvidersByUserProfile(userId).FirstOrDefault();

                    if (userItemProviders == null)
                    {
                        var profile = this._userProfileStore.GetUserProfileById(userId);

                        userItemProviders = DataHelper.TryToInitItemProviderForUser(profile != null ? profile.CompanyName : string.Empty,
                                                                                    string.Empty,
                                                                                    profile != null ? profile.CompanyEmail : string.Empty,
                                                                                    profile != null ? profile.CompanyPhone : string.Empty,
                                                                                    (profile != null && profile.LocationId.HasValue) ? profile.LocationId.Value : 1 /* default */,
                                                                                    userId,
                                                                                    _dataStore);
                    }

                    if (userItemProviders != null)
                    {
                        //base.CurrentLang.Id
                        Item item = new Item();
                        item.Name                   = model.Name;
                        item.Description            = model.Description;
                        item.Gender                 = model.Gender.Value;
                        item.MadeBy                 = model.MadeBy;
                        item.ProvideBy              = model.ProvideBy;
                        item.SuggestionTerms        = model.SuggestionTermsTemperature.Value + model.SuggestionTermsAdditional + model.SuggestionTermsExtra;
                        item.Season                 = model.Season.Value;
                        item.WaterProtectionPercent = model.WaterProtectionPercent;
                        item.IceProtectionPercent   = model.IceProtection;
                        item.ArmoringPercent        = model.ArmoringPercent;
                        item.SunProtectionPercent   = model.SunProtectionPercent;
                        item.MinAge                 = model.MinAge;
                        item.MaxAge                 = model.MaxAge;
                        item.Year                   = new DateTime(model.Year, 1, 1);
                        item.IsPublic               = model.IsPublic;
                        item.ActionTypeId           = model.ActionTypeId.Value;
                        item.LanguageId             = base.CurrentLang.Id; //todo
                        item.IsWardrobe             = true;

                        var context = ModelContainer.Instance.GetInstance <phiContext>();
                        using (var dbContextTransaction = context.Database.BeginTransaction())
                        {
                            try
                            {
                                this._dataStore.Insert(item);

                                // We need an item id to create and link other entities.
                                var pItem = new ProvidersItem
                                {
                                    ItemId          = item.Id,
                                    ItemProvidersId = userItemProviders.ItemProviderId
                                };

                                Image image = new Image
                                {
                                    ImageUrl = model.ImageUrl,
                                    ItemId   = item.Id,
                                    // Height = 0,
                                    // Width = 0
                                };

                                this._dataStore.Insert(pItem);
                                this._dataStore.Insert(image);

                                dbContextTransaction.Commit();
                            }
                            catch (Exception ex)
                            {
                                _logger.Error("Exception HttpPost ManageDress - Transaction Failed On Insert", ex);

                                dbContextTransaction.Rollback();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("Exception HttpPost ManageDres", ex);
                }

                return(RedirectToAction("DressRoom"));
            }

            return(View(model));
        }