コード例 #1
0
        public IHttpActionResult PostSupplement(Supplement supplement)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Supplements.Add(supplement);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (SupplementExists(supplement.Suppl_id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = supplement.Suppl_id }, supplement));
        }
コード例 #2
0
        public void Delete(Supplement supplement)
        {
            Guard.WhenArgument(supplement, "supplement").IsNull().Throw();

            this.supplements.Delete(supplement);
            this.supplements.SaveChanges();
        }
コード例 #3
0
        public IHttpActionResult PutSupplement(string id, Supplement supplement)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != supplement.Suppl_id)
            {
                return(BadRequest());
            }

            db.Entry(supplement).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplementExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public async Task DeleteAsync_WithSupplementId_ShouldDeleteSupplement()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            await managerSupplementService.DeleteAsync(firstNotDeletedSupplementId);

            // Assert
            Supplement supplement = database.Supplements.Find(firstNotDeletedSupplementId);

            supplement.IsDeleted.Should().Be(true);

            foreach (Review review in supplement.Reviews)
            {
                review.IsDeleted.Should().Be(true);
            }

            foreach (Comment comment in supplement.Comments)
            {
                comment.IsDeleted.Should().Be(true);
            }
        }
コード例 #5
0
        public async Task AddSupplementToCartAsync_WithSupplementId_ShouldIncrementQuantityInCartAndReturnTrue()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            Supplement supplement = database.Supplements.Find(supplementId);
            SupplementInCartServiceModel supplementInCart = new SupplementInCartServiceModel
            {
                Id               = supplement.Id,
                Name             = supplement.Name,
                Quantity         = supplement.Quantity,
                Price            = supplement.Price,
                ManufacturerName = supplement.Manufacturer.Name
            };

            ShoppingCart shoppingCart = new ShoppingCart();

            shoppingCart.Supplements.Add(supplementInCart);

            IOrderService orderService = new OrderService(database);

            // Act
            bool result = await orderService.AddSupplementToCartAsync(supplementId, shoppingCart);

            // Assert
            result.Should().Be(true);
            supplementInCart.Quantity.Should().Be(supplement.Quantity + 1);
        }
コード例 #6
0
        public async Task FinishOrderAsync_WithQuantityLessThanAvailable_ShouldReturnFalse()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            Supplement supplement = database.Supplements.Find(supplementId);
            SupplementInCartServiceModel supplementInCart = new SupplementInCartServiceModel
            {
                Id               = supplement.Id,
                Name             = supplement.Name,
                Quantity         = 10,
                Price            = supplement.Price,
                ManufacturerName = supplement.Manufacturer.Name
            };

            ShoppingCart shoppingCart = new ShoppingCart();

            shoppingCart.Supplements.Add(supplementInCart);

            IOrderService orderService = new OrderService(database);

            // Act
            bool result = await orderService.FinishOrderAsync(userId, shoppingCart);

            // Assert
            result.Should().Be(false);
        }
コード例 #7
0
        protected override void ExecuteAddSupplementCommand(string[] commandWords)
        {
            Supplement supplement = null;

            switch (commandWords[1])
            {
            case "Weapon":
                supplement = new Weapon();
                break;

            case "HealthCatalyst":
                supplement = new HealthCatalyst();
                break;

            case "PowerCatalyst":
                supplement = new PowerCatalyst();
                break;

            case "AggressionCatalyst":
                supplement = new AggressionCatalyst();
                break;

            default:
                break;
            }

            if (supplement != null)
            {
                var targetUnit = this.GetUnit(commandWords[2]);
                targetUnit.AddSupplement(supplement);
            }
        }
コード例 #8
0
        private void GetSessionItemsToProperties()
        {
            Supplement supplement = (Supplement)Session["NewSupplement"];
            Dictionary <string, int> categories = (Dictionary <string, int>)Session["Categories"];
            Dictionary <string, int> topics     = (Dictionary <string, int>)Session["Topics"];
            Dictionary <string, int> brands     = (Dictionary <string, int>)Session["Brands"];

            if (supplement == null)
            {
                string errorMessage = string.Format("Session item Supplement is null and can not be edited further.");
                throw new ArgumentException(errorMessage);
            }
            this.NewSupplement = supplement;

            if (categories == null)
            {
                string errorMessage = string.Format("Session item Categories is null and can not be edited further.");
                throw new ArgumentException(errorMessage);
            }
            this.Categories = categories;

            if (topics == null)
            {
                string errorMessage = string.Format("Session item Topics is null and can not be edited further.");
                throw new ArgumentException(errorMessage);
            }
            this.Topics = topics;

            if (brands == null)
            {
                string errorMessage = string.Format("Session item Brands is null and can not be edited further.");
                throw new ArgumentException(errorMessage);
            }
            this.Brands = brands;
        }
コード例 #9
0
        public void RemoveAllSupplementsFromCartAsync_WithSupplementId_ShouldRemoveSupplementFromCartAndReturnTrue()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            Supplement supplement = database.Supplements.Find(supplementId);
            SupplementInCartServiceModel supplementInCart = new SupplementInCartServiceModel
            {
                Id               = supplement.Id,
                Name             = supplement.Name,
                Quantity         = 10,
                Price            = supplement.Price,
                ManufacturerName = supplement.Manufacturer.Name
            };

            ShoppingCart shoppingCart = new ShoppingCart();

            shoppingCart.Supplements.Add(supplementInCart);

            IOrderService orderService = new OrderService(database);

            // Act
            bool result = orderService.RemoveAllSupplementsFromCartAsync(supplementId, shoppingCart);

            // Assert
            result.Should().Be(true);
            shoppingCart.Supplements.Count().Should().Be(0);
        }
コード例 #10
0
        public async Task <bool> AddSupplementToCartAsync(int supplementId, ShoppingCart shoppingCart)
        {
            Supplement supplement = await this.database
                                    .Supplements
                                    .Include(s => s.Manufacturer)
                                    .Where(s => s.Id == supplementId)
                                    .FirstOrDefaultAsync();

            if (supplement.Quantity == 0)
            {
                return(false);
            }

            if (shoppingCart.Supplements.Any(s => s.Id == supplementId))
            {
                shoppingCart.Supplements.Where(s => s.Id == supplementId).FirstOrDefault().Quantity += 1;
            }
            else
            {
                SupplementInCartServiceModel supplementInCart = Mapper.Map <SupplementInCartServiceModel>(supplement);

                supplementInCart.Quantity = 1;

                shoppingCart.Supplements.Add(supplementInCart);
            }

            return(true);
        }
コード例 #11
0
        private Supplement CreateNewEmptySupplement()
        {
            //,[Name]
            //,[ImageUrl]
            //,[Ingredients]
            //,[Use]
            //,[Description]
            //,[CreationDate]
            //,[AuthorId]
            //,[CategoryId]
            //,[TopicId]
            //,[BrandId]
            Supplement newSupplement = new Supplement();

            newSupplement.Id           = null;
            newSupplement.Name         = string.Empty;
            newSupplement.ImageUrl     = string.Empty;
            newSupplement.Ingredients  = string.Empty;
            newSupplement.Use          = string.Empty;
            newSupplement.Description  = string.Empty;
            newSupplement.CreationDate = DateTime.Now;

            //newSupplement.AuthorId = Guid.Parse(this.User.Identity.GetUserId());
            //newSupplement.AuthorId = (this.User.Identity.GetUserId());
            newSupplement.AuthorId   = null;
            newSupplement.CategoryId = -1;
            newSupplement.TopicId    = -1;
            newSupplement.BrandId    = -1;

            return(newSupplement);
        }
コード例 #12
0
        public async Task <Supplement> Update(string id, Supplement s)
        {
            // Updates and existing supplement.
            await _supplement.ReplaceOneAsync(su => su.Id == id, s);

            return(s);
        }
コード例 #13
0
        internal void IncreaseQuantityOf(object product, int categoryIndex, int quantity)
        {
            using (shopContext = new ShopContext())
            {
                switch (categoryIndex)
                {
                case 0:
                    Supplement supplement          = (Supplement)product;
                    Supplement supplementToReplace = shopContext.Supplement.Find(supplement.Id);
                    supplement.Quantity += quantity;
                    shopContext.Entry(supplementToReplace).Entity.Quantity = supplement.Quantity;
                    break;

                case 1:
                    Drink drink          = (Drink)product;
                    Drink drinkToReplace = shopContext.Drinks.Find(drink.Id);
                    drink.Quantity += quantity;
                    shopContext.Entry(drinkToReplace).Entity.Quantity = drink.Quantity;
                    break;

                case 2:
                    Equipment equipment          = (Equipment)product;
                    Equipment equipmentToReplace = shopContext.Equipment.Find(equipment.Id);
                    equipment.Quantity += quantity;
                    shopContext.Entry(equipmentToReplace).Entity.Quantity = equipment.Quantity;
                    break;
                }
                shopContext.SaveChanges();
            }
        }
コード例 #14
0
        public async Task <Supplement> Create(Supplement s)
        {
            //Create a supplement.
            await _supplement.InsertOneAsync(s);

            return(s);
        }
コード例 #15
0
        public override void Execute()
        {
            if (String.IsNullOrWhiteSpace(Supplement))
            {
                throw new CommandException(
                          $"Please enter a valid supplement for the command \"{Body}\""
                          );
            }

            if (Program.CurrentAutomata != null)
            {
                if (File.Exists(Supplement))
                {
                    var fileNameWithoutSulfix = Path.GetFileNameWithoutExtension(Supplement).Split('.').First();
                    var reader  = new AutomataReader(Program.CurrentAutomata);
                    var results = reader.MatchAll(File.ReadAllLines(Supplement));

                    using (var writer = new StreamWriter(Supplement.Replace($"{fileNameWithoutSulfix}.IN", $"{ fileNameWithoutSulfix }.OUT"))){
                        writer.Write(results);
                    }
                }
                else
                {
                    Program.LogError($"File \"{Supplement}\" does not exist.");
                }
            }
            else
            {
                Program.LogError("Can't load input. Automata not set.");
            }
        }
コード例 #16
0
ファイル: InvoicesController.cs プロジェクト: zeldax54/GProy
        // POST: Invoices/Delete/5

        //Eliminar factura

        public void DeleteConfirmed(int id)
        {
            Invoice invoice = db.Invoice.Find(id);

            //Actualizando el Detalle
            ProjectDetails pd = db.ProjectDetails.Find(invoice.InvoiceProjectDetails.First().ProjectDetailsSpecialist.projectDetailsId);

            pd.totalInvoiced = pd.totalInvoiced - invoice.amount;
            pd.toInvoice     = pd.totalContracted - pd.totalInvoiced;
            //Actualizar Proyecto
            pd.ProjSup.Project.totalnvoiced = decimal.Parse((pd.totalInvoiced - invoice.amount).ToString());
            pd.ProjSup.Project.toInvoiced   = decimal.Parse((pd.totalContracted - pd.totalInvoiced).ToString());
            //Actualizar Estado del SUplemento

            Supplement s         = pd.ProjSup.Supplement;
            double     facturado = s.ProjSup.Sum(z => z.ProjectDetails.Sum(ss => ss.totalInvoiced));

            if (Math.Abs(facturado - decimal.ToDouble(s.amount)) < 0.1)
            {
                foreach (var state in s.StateCSupplement)
                {
                    state.state = false;
                }
                StateC           terminado        = db.StateC.Find(10);
                StateCSupplement stateCSupplement = new StateCSupplement
                {
                    stateCId    = terminado.stateCId,
                    Supplement  = s,
                    date        = DateTime.Now,
                    description = "Maximo de facturacion alcanzada",
                    state       = true
                };
                db.StateCSupplement.Add(stateCSupplement);
            }
            else
            {
                if (s.StateCSupplement.First(a => a.state).stateCId == 10)
                {
                    foreach (var state in s.StateCSupplement)
                    {
                        state.state = false;
                    }
                    StateC           iniciado         = db.StateC.Find(5);
                    StateCSupplement stateCSupplement = new StateCSupplement
                    {
                        stateCId    = iniciado.stateCId,
                        Supplement  = s,
                        date        = DateTime.Now,
                        description = "Estado cambiado dinamicamente x Ediacion de Facturas",
                        state       = true
                    };
                    db.StateCSupplement.Add(stateCSupplement);
                }
            }

            db.InvoiceProjectDetails.RemoveRange(invoice.InvoiceProjectDetails);
            db.InvoiceStateSet.RemoveRange(invoice.InvoiceStateSet);
            db.Invoice.Remove(invoice);
            db.SaveChanges();
        }
コード例 #17
0
        public async Task IsLastAvailableSupplementAlreadyAdded_WithSupplementIdAndShoppingCartWithSupplement_ShouldReturnTrue()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            Supplement supplement = database.Supplements.Find(supplementId);
            SupplementInCartServiceModel supplementInCart = new SupplementInCartServiceModel
            {
                Id               = supplement.Id,
                Name             = supplement.Name,
                Quantity         = 1,
                Price            = supplement.Price,
                ManufacturerName = supplement.Manufacturer.Name
            };

            ShoppingCart shoppingCart = new ShoppingCart();

            shoppingCart.Supplements.Add(supplementInCart);

            IOrderService orderService = new OrderService(database);

            // Act
            bool result = await orderService.IsLastAvailableSupplementAlreadyAdded(supplementId, shoppingCart);

            // Assert
            result.Should().Be(true);
        }
コード例 #18
0
        //update
        internal void DecreaseQuantityOf(object product, int quantity = 1)
        {
            using (var shopContext = new ShopContext())
            {
                dynamic updater;
                switch (product.GetType().Name.ToString())
                {
                case "Supplement":
                    Supplement supplement = (Supplement)product;
                    updater           = shopContext.Supplement.FirstOrDefault(s => s.Id == supplement.Id);
                    updater.Quantity -= quantity;
                    break;

                case "Drink":
                    Drink drink = (Drink)product;
                    updater           = shopContext.Drinks.FirstOrDefault(s => s.Id == drink.Id);
                    updater.Quantity -= quantity;
                    break;

                case "Equipment":
                    Equipment equipment = (Equipment)product;
                    updater           = shopContext.Equipment.FirstOrDefault(s => s.Id == equipment.Id);
                    updater.Quantity -= quantity;
                    break;
                }
                shopContext.SaveChanges();
            }
        }
コード例 #19
0
        public async Task <Supplement> Create(Supplement supplement)
        {
            List <Task> tasks = new List <Task>();

            var dietIdExists = _dietRepository.GetById(supplement.SuitableDietId);

            tasks.Add(dietIdExists);
            var uniqueId = _supplementRepository.GetById(supplement.Id);

            tasks.Add(uniqueId);
            var uniqueName = _supplementRepository.GetByName(supplement.Name);

            tasks.Add(uniqueName);

            await Task.WhenAll(tasks);

            if (dietIdExists.Result != null && uniqueId.Result == null && uniqueName.Result == null)
            {
                return(await _supplementRepository.Create(supplement));
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #20
0
        /// <summary>
        /// Gets the index of the element in ShoppingCartList where product's id equals element's id.
        /// </summary>
        /// <param name="product">Product to be searched for.</param>
        internal static int IndexOfProductInCart(object product, int categoryIndex)
        {
            switch (categoryIndex)
            {
            case SupplementIndex:
                Supplement supplement = (Supplement)product;
                for (int i = 0; i < ShoppingCartList.Count; i++)
                {
                    try
                    {
                        if (((Supplement)ShoppingCartList[i]).Id == supplement.Id)
                        {
                            return(i);
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                break;

            case drinksIndex:
                Drink drink = (Drink)product;
                for (int i = 0; i < ShoppingCartList.Count; i++)
                {
                    try
                    {
                        if (((Drink)ShoppingCartList[i]).Id == drink.Id)
                        {
                            return(i);
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                break;

            case equipmentsIndex:
                Equipment equipment = (Equipment)product;
                for (int i = 0; i < ShoppingCartList.Count; i++)
                {
                    try
                    {
                        if (((Equipment)ShoppingCartList[i]).Id == equipment.Id)
                        {
                            return(i);
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                break;
            }
            return(int.MaxValue);
        }
コード例 #21
0
        public ActionResult DeleteConfirmed(int id, bool idclient, int stateC, DateTime dateState, string descriptionState)
        {
            Supplement supplement = db.Supplement.Find(id);
            //int contractId = supplement.contractId;
            //List<ClientSupplement> listClientS =
            //                db.ClientSupplement.Where(c => c.supplementId == supplement.supplementId).ToList();
            //if (listClientS.Any())
            //{
            //    int count = listClientS.Count;
            //    for (int i = 0; i < count; i++)
            //    {
            //        db.ClientSupplement.Remove(listClientS[i]);
            //    }
            //}
            //List<StateCSupplement> listStateCSupplements =
            //                db.StateCSupplement.Where(s => s.supplementId == supplement.supplementId).ToList();
            //if (listStateCSupplements.Any())
            //{
            //    int count = listStateCSupplements.Count;
            //    for (int i = 0; i < count; i++)
            //    {
            //        db.StateCSupplement.Remove(listStateCSupplements[i]);
            //    }
            //}
            List <StateCSupplement> stateCSupplement =
                db.StateCSupplement.Where(st => st.supplementId == supplement.supplementId).ToList();
            bool found = false;

            foreach (StateCSupplement stateCs in stateCSupplement)
            {
                if (stateCs.stateCId == stateC)
                {
                    found               = true;
                    stateCs.state       = true;
                    stateCs.date        = dateState;
                    stateCs.description = descriptionState;
                }
                else
                {
                    stateCs.state = false;
                }
            }
            if (!found)
            {
                StateCSupplement _stateCSupplement = new StateCSupplement
                {
                    stateCId    = stateC,
                    Supplement  = supplement,
                    date        = dateState,
                    description = descriptionState,
                    state       = true
                };
                db.StateCSupplement.Add(_stateCSupplement);
            }


            db.SaveChanges();
            return(RedirectToAction("Index", new { id = supplement.contractId, idclient = idclient }));
        }
コード例 #22
0
 public DeleteSupplementCommand(Supplement parent, SupplementItem supplementItem)
 {
     if (parent.ReadOnly)
     {
         throw new ApsimXException(parent, string.Format("Unable to delete {0} - it is read-only.", parent.Name));
     }
     this.parent             = parent;
     this.supplementToDelete = supplementItem;
 }
コード例 #23
0
 public AddSupplementCommand(Supplement parent, string suppName)
 {
     if (parent.ReadOnly)
     {
         throw new ApsimXException(parent, string.Format("Unable to add supplement to {0} - it is read-only.", parent.Name));
     }
     this.parent         = parent;
     this.supplementName = suppName;
 }
コード例 #24
0
 /// <summary>Constructor.</summary>
 /// <param name="parent">The old index.</param>
 /// <param name="supplements">List of supplements to reset</param>
 public ResetSupplementCommand(Supplement parent, List <SupplementItem> supplements)
 {
     if (parent.ReadOnly)
     {
         throw new ApsimXException(parent, string.Format("Unable to reset {0} - it is read-only.", parent.Name));
     }
     this.parent   = parent;
     this.suppList = supplements;
 }
コード例 #25
0
 public SupplementInfo(Guid id, string name, string description, List <DayOfWeek> dayOfSupplement, Supplement supplement, List <HourInfo> timeRanges = null)
 {
     Id              = id;
     Name            = name;
     Description     = description;
     DayOfSupplement = dayOfSupplement;
     Supplement      = supplement;
     TimeRanges      = timeRanges;
 }
コード例 #26
0
ファイル: AdminController.cs プロジェクト: Pizayn/FitBody
 public IActionResult SupplementEdit(Supplement supplement)
 {
     if (ModelState.IsValid)
     {
         _supplementService.Update(supplement);
         TempData.Add("message", "Supplement successfully updated ");
     }
     return(RedirectToAction("Supplement"));
 }
コード例 #27
0
 /// <summary>Constructor.</summary>
 /// <param name="parent">The Supplement model.</param>
 /// <param name="oldIdx">The old index.</param>
 /// <param name="newIdx">The new index.</param>
 public SelectSupplementCommand(Supplement parent, int oldIdx, int newIdx)
 {
     if (parent.ReadOnly)
     {
         throw new ApsimXException(parent, string.Format("Unable to select supplement in {0} - it is read-only.", parent.Name));
     }
     this.parent      = parent;
     this.prevSuppIdx = oldIdx;
     this.newSuppIdx  = newIdx;
 }
コード例 #28
0
        private bool CheckIfSupplementIsModified(Supplement supplement, string name, string description, int quantity, decimal price, byte[] picture, DateTime bestBeforeDate, int subcategoryId, int manufacturerId)
        {
            if (name == supplement.Name && description == supplement.Description && quantity == supplement.Quantity &&
                price == supplement.Price && picture.SequenceEqual(supplement.Picture) && bestBeforeDate.Date == supplement.BestBeforeDate.Date &&
                subcategoryId == supplement.SubcategoryId && manufacturerId == supplement.ManufacturerId)
            {
                return(false);
            }

            return(true);
        }
コード例 #29
0
        /// <summary>
        /// Attach the model and view to this presenter.
        /// </summary>
        /// <param name="model">The initial supplement model</param>
        /// <param name="view">The supplement view to work with</param>
        /// <param name="explrPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explrPresenter)
        {
            supplement        = model as Supplement;
            supplementView    = view as SupplementView;
            explorerPresenter = explrPresenter;

            ConnectViewEvents();
            PopulateView();

            explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;
        }
コード例 #30
0
        /// <summary>
        /// Increases the quantity of a product in shopping cart if exists by name.
        /// Returns true if quantity increasement succeeded, else false.
        /// </summary>
        /// <param name="product">Product to be found</param>
        /// <param name="quantity">The quantity, which would be added</param>
        internal bool IncreaseQuantityOfCartProductIfExists(object product, int categoryIndex, int quantity = 1)
        {
            using (shopContext = new ShopContext())
            {
                bool isProductInCart = false;
                switch (categoryIndex)
                {
                case 0:
                    Supplement supplement = (Supplement)product;
                    foreach (var productInCart in shopContext.Cart.ToList())
                    {
                        if (productInCart.Name == supplement.Name)
                        {
                            productInCart.Quantity += quantity;
                            isProductInCart         = true;
                            break;
                        }
                    }
                    break;

                case 1:
                    Drink drink = (Drink)product;
                    foreach (var productInCart in shopContext.Cart.ToList())
                    {
                        if (productInCart.Name == drink.Name)
                        {
                            productInCart.Quantity += quantity;
                            isProductInCart         = true;
                            break;
                        }
                    }
                    break;

                case 2:
                    Equipment equipment = (Equipment)product;
                    foreach (var productInCart in shopContext.Cart)
                    {
                        if (productInCart.Name == equipment.Name)
                        {
                            productInCart.Quantity += quantity;
                            isProductInCart         = true;
                            break;
                        }
                    }
                    break;
                }
                if (isProductInCart)
                {
                    shopContext.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }
コード例 #31
0
 //ADD Supplement
 public void AddSupplement(Supplement supplement)
 {
     _unitOfWork.SupplementRepository.Add(supplement);
     _unitOfWork.SaveChanges();
 }
コード例 #32
0
 //UPDATE Supplement
 public void UpdateSupplement(Supplement supplement)
 {
     _unitOfWork.SupplementRepository.Update(supplement);
     _unitOfWork.SaveChanges();
 }
コード例 #33
0
ファイル: Drive.cs プロジェクト: skarllot/zbxlld
        private bool TryGetVolumesViaWmi(out Supplement.IVolumeInfo[] vols)
        {
            vols = null;

            try
            {
                vols = Supplement.Win32_Volume.GetAllVolumes();
            }
            catch (System.OutOfMemoryException e)
            {
                if (MainClass.DEBUG)
                {
                    MainClass.WriteLogEntry(string.Format("{0}.GetOutput: Out of memory exception.", CLASS_FULL_PATH));
                    MainClass.WriteLogEntry("Exception:");
                    MainClass.WriteLogEntry(e.ToString());
                }
                // TODO: Make a proper exit
                Console.WriteLine("You have insufficient permissions or insufficient memory.");
                Environment.Exit((int)ErrorId.GetAllVolumesOutOfMemory);
            }
            catch (Exception e)
            {
                if (MainClass.DEBUG)
                {
                    MainClass.WriteLogEntry(string.Format(
                        "{0}.GetOutput: Unexpected exception.", CLASS_FULL_PATH));
                    MainClass.WriteLogEntry("Exception:");
                    MainClass.WriteLogEntry(e.ToString());
                }
                vols = null;
                return false;
            }

            return true;
        }
コード例 #34
0
 //DELETE Supplement
 public void DeleteSupplement(Supplement supplement)
 {
     _unitOfWork.SupplementRepository.Remove(supplement);
     _unitOfWork.SaveChanges();
 }