コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ItemName,UnitOfMeasureId,CostCategoryId")] CostItem costItem)
        {
            if (id != costItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                CostItem ExistingItem = _context.CostItem.FirstOrDefault(ci => ci.ItemName.ToUpper() == costItem.ItemName.ToUpper());

                if (ExistingItem == null)
                {
                    _context.Update(costItem);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(View("EditDuplicate", costItem));
                }
            }

            ViewData["CostCategoryId"]  = new SelectList(_context.CostCategory.OrderBy(cc => cc.CategoryName), "Id", "CategoryName", costItem.CostCategoryId);
            ViewData["UnitOfMeasureId"] = new SelectList(_context.UnitOfMeasure.OrderBy(um => um.UnitName), "Id", "UnitName", costItem.UnitOfMeasureId);
            return(View(costItem));
        }
コード例 #2
0
        public async Task <ActionResult <CostItemViewModel> > Add([FromBody] CostItemCreateViewModel model)
        {
            var entity = new CostItem
            {
                Amount     = model.Amount,
                CostTypeId = model.CostTypeId,
                DateUsed   = model.DateUsed,
                ItemName   = model.ItemName
            };

            var costTypes = await _costTypesRepository.GetAll();

            if (costTypes.Any(x => x.CostTypeId == model.CostTypeId) == false)
            {
                return(NotFound("CostTypeId does not exist"));
            }

            var record = await _costItemsRepository.Add(entity);

            return(CreatedAtRoute("GetById",
                                  new { Id = record.CostItemId },
                                  new CostItemViewModel
            {
                CostItemId = record.CostItemId,
                ItemName = record.ItemName,
                CostType = AdaptToCostTypeViewModel(costTypes, record.CostTypeId),
                Amount = record.Amount,
                DateUsed = record.DateUsed
            }));
        }
コード例 #3
0
        /// <summary>
        /// 添加和修改
        /// </summary>
        /// <returns></returns>
        public ActionResult SaveData()
        {
            string   result    = "";
            string   dataitem  = Request["CostItem"];
            string   savetype  = Request["savetype"].ToString().Trim();
            CostItem model_lgt = JsonConvert.DeserializeObject <CostItem>(dataitem);

            if (savetype == "add")
            {
                var costitem = CostItemService.LoadEntities(a => a.Code == model_lgt.Code).FirstOrDefault();
                if (costitem != null)
                {
                    result = "编号已存在,请重新填写!";
                    return(Content(result.ToString()));
                }
                CostItemService.AddEntity(model_lgt);
                result = "保存成功!";
            }
            else if (savetype == "edit")
            {
                if (CostItemService.EditEntity(model_lgt))
                {
                    result = "编辑成功!";
                }
                else
                {
                    result = "编辑失败!";
                }
            }
            return(Content(result.ToString()));
        }
コード例 #4
0
        public IHttpActionResult Post(CostItem baseRequest)
        {
            baseRequest.OrgId = SecurityHelper.CurrentPrincipal.OrgId;
            var response = service.SaveCostItem(baseRequest);

            return(Ok(response));
        }
コード例 #5
0
        public async Task <List <CostItem> > AddUpdateCostItems(List <CostItem> items)
        {
            List <CostItem> citems = new List <CostItem>();
            CostItem        citem  = null;

            foreach (var item in items)
            {
                if (item.id == 0)
                {
                    citem = await AddCostItems(item);

                    citems.Add(citem);
                }
                else if (item.id > 0 && item.status == 2)
                {
                    citem = await UpdateCostItems(item);

                    citems.Add(citem);
                }
            }
            //await _context.CostItem.AddRangeAsync(items);
            //await _context.SaveChangesAsync();
            //if (items.Count > 0)
            //    citems = await GetCostItems(items[0].serviceid);
            return(citems);
        }
コード例 #6
0
        public QueueExecutorLoadInfo GetCurrentLoad()
        {
            if (costList.Count == 0)
            {
                return(QueueExecutorLoadInfo.CreateEmptyLoad(StatisticalPeriod));
            }
            DateTime dt    = DateTime.UtcNow;
            CostItem first = costList.FirstOrDefault();

            if (first == null)
            {
                return(QueueExecutorLoadInfo.CreateEmptyLoad(StatisticalPeriod));
            }

            long totalBusy = costList.Sum(c => c.Cost);

            DateTime beginTime = dt.Add(-StatisticalPeriod);

            if (beginTime > first.BeginTime)
            {
                beginTime = first.BeginTime;
            }
            TimeSpan realPeriod = dt - beginTime;

            double length = realPeriod.TotalMilliseconds;

            return(new QueueExecutorLoadInfo()
            {
                Busy = totalBusy,
                Idle = length - totalBusy,
                LoadRatio = totalBusy / length,
                Counter = _periodCounter
            });
        }
コード例 #7
0
        /// <summary>
        /// 删除成本项
        /// </summary>
        /// <param name="id">Id</param>
        public void Delete(string id)
        {
            using (DbConnection conn = DbHelper.CreateConnection())
            {
                DbTransaction trans = null;
                try
                {
                    conn.Open();
                    trans = conn.BeginTransaction();

                    CostItem oldEntity = this.Select(trans, id);
                    // 检查Code是否已使用
                    this.costItemRepository.Delete(trans, id);

                    trans.Commit();
                }
                catch (EasySoftException ex)
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw ex;
                }
                catch (Exception ex)
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw ex;
                }
            }
        }
コード例 #8
0
        public async Task <IActionResult> PutCostItem(string id, CostItem costItem)
        {
            if (id != costItem.Id)
            {
                return(BadRequest());
            }



            _context.Entry(costItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CostItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #9
0
        /// <summary>
        /// 新增成本项
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="name">名称</param>
        /// <param name="isValid">是否有效</param>
        /// <param name="mender">创建人</param>
        public void Update(string id, string name, string isValid, short orderNumber, string remark, string mender)
        {
            using (DbConnection conn = DbHelper.CreateConnection())
            {
                DbTransaction trans = null;
                try
                {
                    conn.Open();
                    trans = conn.BeginTransaction();

                    CostItem entity = this.Select(trans, id);
                    entity.Update(name, isValid, orderNumber, remark, mender);
                    this.costItemRepository.Update(trans, entity);

                    trans.Commit();
                }
                catch (EasySoftException ex)
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw ex;
                }
                catch (Exception ex)
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw ex;
                }
            }
        }
コード例 #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            CostItem costItem = _costItemService.GetById(id);
            var      user     = _userService.GetUserDataForVersion();
            var      recycleBinInDBRelation = _serviceService.HasRecycleBinInDBRelation(costItem);

            if (recycleBinInDBRelation.hasRelated == false)
            {
                var recycleToRecycleBin = _costItemService.RecycleToRecycleBin(costItem.ID, user.Item1, user.Item2);
                if (!recycleToRecycleBin.toRecycleBin)
                {
                    ViewBag.RecycleBinError =
                        "Невозможно удалить, так как на удаляемый элемент ссылаются другие элементы в системе." +
                        "Сначала необходимо удалить элементы, которые ссылаются на данный элемент. " +
                        recycleToRecycleBin.relatedClassId;
                    return(View(costItem));
                }
            }
            else
            {
                ViewBag.RecycleBinError =
                    "Невозможно удалить, так как на удаляемый элемент ссылаются другие элементы в системе." +
                    $"Сначала необходимо удалить элементы, которые ссылаются на данный элемент. {recycleBinInDBRelation.relatedInDBClassId}";
                return(View(costItem));
            }
            return(RedirectToAction("Index"));
        }
コード例 #11
0
        private CostItem CreateModel(CostItem costItem, CostItemBindingModel model, UrskiyPeriodDatabase context)
        {
            costItem = CreateModel(costItem, model);

            if (model.Id.HasValue)
            {
                var routeCost = context.CostItemRoutes.Where(rec =>
                                                             rec.CostItemId == model.Id.Value).ToList();
                // удаляем те, которых нет в модели
                context.CostItemRoutes.RemoveRange(routeCost.Where(rec =>
                                                                   !model.CostItemRoute.ContainsKey(rec.RouteId)).ToList());
                context.SaveChanges();

                foreach (var Reserve in routeCost)
                {
                    model.CostItemRoute.Remove(Reserve.RouteId);
                }
            }

            foreach (var cost in model.CostItemRoute)
            {
                context.CostItemRoutes.Add(new CostItemRoute
                {
                    CostItemId = costItem.Id,
                    RouteId    = cost.Key
                });
            }
            context.SaveChanges();
            return(costItem);
        }
コード例 #12
0
        private static void ProcessParts(CostModel model, List <TDil> dily, CostItem parent, Dictionary <string, ClassificationItem> map)
        {
            if (dily == null)
            {
                return;
            }
            foreach (var dil in dily)
            {
                // grouping level in the cost breakdown hierarchy
                var item = new CostItem(model)
                {
                    Name        = dil.Nazev,
                    Identifier  = dil.Cislo,
                    Description = dil.DPOPIS,
                    Type        = dil.Typ.ToString()
                };
                parent.Children.Add(item);

                // additional properties can be stored in custom property sets
                // item["CZ_CostItem"] = new PropertySet(model);

                // leafs in the cost breakdown hierarchy
                ProcessItems(model, dil.POLOZKA, item, map);
            }
        }
コード例 #13
0
        private void AddHopeItem()
        {
            CostItem item = new CostItem();

            HopeItemContext.Children.Add(item);

            item.LayoutTransform = new ScaleTransform(1f, 0f);
        }
コード例 #14
0
 public ActionResult Edit(CostItem costItem)
 {
     if (ModelState.IsValid)
     {
         _costItemService.Update(costItem);
         return(RedirectToAction("Index"));
     }
     return(View(costItem));
 }
コード例 #15
0
ファイル: Item.cs プロジェクト: SergioRibera/inventory-system
 public Item(int i, string n, string desc, string s)
 {
     id              = i;
     name            = n;
     description     = desc;
     sellerDialog    = s;
     collectableData = new ItemCollectable();
     cost            = new CostItem();
 }
コード例 #16
0
        private void UpdateItemScale()
        {
            for (int i = 0; i < HopeItemContext.Children.Count; ++i)
            {
                CostItem item = ((CostItem)HopeItemContext.Children[i]);

                item.scale          += (1f - item.scale) * 0.2f;
                item.LayoutTransform = new ScaleTransform(1f, item.scale);
            }
        }
コード例 #17
0
        /// <summary>
        /// 根据Id查找一条数据
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns>返回成本记录</returns>
        internal CostItem Select(DbTransaction trans, string id)
        {
            CostItem entity = this.costItemRepository.Select(trans, id);

            if (entity == null)
            {
                throw new EasySoftException(BusinessResource.Common_NoFoundById);
            }
            return(entity);
        }
コード例 #18
0
        public async Task <IActionResult> Create([Bind("Id,Name")] CostItem costItem)
        {
            if (ModelState.IsValid)
            {
                await _costItemsService.AddAsync(costItem);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(costItem));
        }
コード例 #19
0
 CostItemViewModel ConvertEntityToViewModel(CostItem model, List <CostType> costTypes)
 {
     return(new CostItemViewModel
     {
         CostItemId = model.CostItemId,
         ItemName = model.ItemName,
         CostType = ConvertEntityToViewModel(costTypes.Single(c => c.CostTypeId == model.CostTypeId)),
         Amount = model.Amount,
         DateUsed = model.DateUsed
     });
 }
コード例 #20
0
        public CostItemsControllerTests()
        {
            var mockingEntities = new MockingEntities <CostItem,
                                                       CostItemsController,
                                                       ICostItemsService>();

            mock               = mockingEntities.Mock;
            validController    = mockingEntities.ValidController;
            notValidController = mockingEntities.NotValidController;
            entity             = mockingEntities.singleEntity;
        }
コード例 #21
0
        public async Task <CostItem> AddCostItems(CostItem item)
        {
            CostItem citem = null;
            //await _context.CostItem.AddRangeAsync(items);
            await _context.CostItem.AddAsync(item);

            await _context.SaveChangesAsync();

            citem = await GetCostItem(item.id);

            return(citem);
        }
コード例 #22
0
        private static void ProcessObjects(CostModel model, CostSchedule schedule, IEnumerable <TObjekt> objekty, Dictionary <string, ClassificationItem> jkso)
        {
            if (objekty == null || !objekty.Any())
            {
                return;
            }

            foreach (var obj in objekty)
            {
                // root element of the cost schedule
                var rootItem = new CostItem(model)
                {
                    Name        = obj.Nazev,
                    Description = obj.OPOPIS,
                    Identifier  = obj.Cislo
                };
                schedule.CostItems.Add(rootItem);

                // additional properties can be stored in custom property sets
                rootItem["CZ_CostItem"] = new PropertySet(model);
                rootItem["CZ_CostItem"]["Charakteristika"]  = new IfcText(obj.Charakteristika);
                rootItem["CZ_CostItem"]["DruhStavebniAkce"] = new IfcText(obj.DruhStavebniAkce);

                if (!string.IsNullOrWhiteSpace(obj.CisloJKSO))
                {
                    var jksoItem = jkso[obj.CisloJKSO];
                    rootItem.ClassificationItems.Add(jksoItem);
                }

                foreach (var soup in obj.SOUPIS)
                {
                    var item = new CostItem(model)
                    {
                        Name        = soup.Nazev,
                        Identifier  = soup.Cislo,
                        Description = soup.RPOPIS
                    };
                    rootItem.Children.Add(item);

                    // classification hierarchy in IFC. Cost Items will be related to Classification Items
                    var classificationMap = new Dictionary <string, ClassificationItem>();
                    if (soup.ZATRIDENI != null && soup.ZATRIDENI.Any())
                    {
                        var rootClassificationName = GetClassificationName(soup);
                        var rootClassification     = new Classification(model, rootClassificationName);
                        classificationMap = ConvertClassification(model, soup.ZATRIDENI, rootClassification.Children);
                    }

                    // next level of the cost breakdown structure
                    ProcessParts(model, soup.DIL, item, classificationMap);
                }
            }
        }
コード例 #23
0
        //public async Task<DeleteResult> RemoveBiller(string id)
        //{
        //    return await _context.Billers.Remove(
        //                 Builders<Biller>.Filter.Eq(s => s._id, id));
        //}

        public async Task <CostItem> UpdateCostItems(CostItem item)
        {
            var citem = _context.CostItem.FirstOrDefault(c => c.id == item.id);

            citem.status = item.status;

            await _context.SaveChangesAsync();

            citem = await GetCostItem(item.id);

            return(citem);
        }
コード例 #24
0
 public bool Insert(CostItem costItem)
 {
     try
     {
         _costItems.Add(costItem);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #25
0
        public async Task <CostItem> Add(CostItem costItem)
        {
            return(await Task.Run(() =>
            {
                if (costItem.CostItemId == Guid.Empty)
                {
                    costItem.CostItemId = Guid.NewGuid();
                }

                _costItems.Add(costItem);
                return costItem;
            }));
        }
コード例 #26
0
        public void CanBeSerialized()
        {
            //Arrange
            var sut = new CostItem("label", "value", "identifier");

            //Act
            var payload = JsonSerializer.Serialize(sut, new JsonSerializerOptions {
                IgnoreNullValues = true
            });

            //Assert
            Assert.NotNull(JsonDocument.Parse(payload));
        }
コード例 #27
0
        public async Task Update(CostItem costItem)
        {
            await Task.Run(() =>
            {
                var idx = _costItems.FindIndex(x => x.CostItemId == costItem.CostItemId);

                if (idx == -1)
                {
                    throw new KeyNotFoundException();
                }

                _costItems[idx] = costItem;
            });
        }
コード例 #28
0
        public void CanBeConstructed()
        {
            //Arrange
            CostItem sut;

            //Act
            sut = new CostItem("label", "value", "identifier");

            //Assert
            Assert.NotNull(sut);
            Assert.Equal("identifier", sut.CapabilityIdentifier);
            Assert.Equal("label", sut.Label);
            Assert.Equal("value", sut.Value);
        }
コード例 #29
0
        public bool Delete(CostItem costItem)
        {
            try
            {
                _costItems.Attach(costItem);
                _costItems.Remove(costItem);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #30
0
        private static void ProcessItems(CostModel model, List <TPolozka> polozky, CostItem parent, Dictionary <string, ClassificationItem> map)
        {
            if (polozky == null)
            {
                return;
            }
            foreach (var polozka in polozky)
            {
                var item = new CostItem(model)
                {
                    Name        = polozka.Nazev,
                    Identifier  = polozka.Cislo,
                    Description = polozka.PPOPIS,
                    Type        = polozka.Typ.ToString()
                };

                // unit cost. There might be more than one or it can be modeled as a hierarchy with operators
                var unitCost = new CostValue(model)
                {
                    Value = System.Convert.ToDouble(polozka.JCena)
                };
                // in the base case there is just one
                item.UnitValues.Add(unitCost);

                // Quantities have measure type and unit, if it is not cost
                AddQuantity(model, item, polozka.MJ, System.Convert.ToDouble(polozka.Mnozstvi));

                // additional properties can be stored in custom property sets
                item["CZ_CostItem"] = new PropertySet(model);
                item["CZ_CostItem"]["JHmotnost"]           = new IfcMassMeasure(System.Convert.ToDouble(polozka.JHmotnost));
                item["CZ_CostItem"]["JDemontazniHmotnost"] = new IfcMassMeasure(System.Convert.ToDouble(polozka.JDemontazniHmotnost));
                item["CZ_CostItem"]["SazbaDPH"]            = new IfcRatioMeasure(System.Convert.ToDouble(polozka.SazbaDPH) / 100);
                item["CZ_CostItem"]["ObchNazev"]           = new IfcIdentifier(polozka.ObchNazev);
                item["CZ_CostItem"]["ObchNazevAN"]         = new IfcBoolean(polozka.ObchNazevAN);
                item["CZ_CostItem"]["PoradoveCislo"]       = new IfcInteger(polozka.PoradoveCislo);
                parent.Children.Add(item);

                // Deprecated: using IFC GlobalId
                // item["CZ_CostItem"]["UID"] = new IfcIdentifier(polozka.UID);

                // assign classification item if defined
                if (
                    !string.IsNullOrWhiteSpace(polozka.PolozkaZatrideniUID) &&
                    map.TryGetValue(polozka.PolozkaZatrideniUID, out ClassificationItem ci))
                {
                    item.ClassificationItems.Add(ci);
                }
            }
        }
コード例 #31
0
 /// <summary>
 /// 初始化引用变量
 /// </summary>
 public NewCostItemEventArgs()
 {
     CostItem = new CostItem();
 }
コード例 #32
0
 public CostItemViewModel(CostItem model,MenuItem menuItem)
 {
     Model = model;
     _menuItem = menuItem;
 }