bool IBuyItemUseCase.Buy(string itemId)
        {
            var itemInfo = _itemRepository.GetItemInfo(itemId, _item.Num(itemId));

            if (!_moneyDecreasable.TryDecrease(itemInfo.Cost))
            {
                return(false);
            }
            _item.Add(itemId, itemInfo.Performance);
            return(true);
        }
Exemple #2
0
 public IActionResult Create([Bind("itemID,itemcategoryID,itemName,price")] Item model, IFormFile imageFile)
 {
     if (ModelState.IsValid)
     {
         if (imageFile != null)
         {
             using (var ms = new MemoryStream())
             {
                 imageFile.CopyTo(ms);
                 model.itemImage = ms.ToArray();
             }
         }
         _Item.Add(model);
         return(RedirectToAction("Index"));
     }
     ViewBag.ItemCategories = _ItemCategory.GetItemCategories;
     return(View(model));
 }
Exemple #3
0
 /// <summary>
 /// Executes the action.
 /// </summary>
 public void Execute()
 {
     _item.Add();
 }
Exemple #4
0
 /// <summary>
 /// Undoes the action.
 /// </summary>
 public void Undo()
 {
     _item.Add();
 }
        public async Task <IActionResult> UpdateCell()
        {
            try
            {
                string requestGuid = Common.GetGuidFromURL(Request.Path.ToString()); //Get guid from query string
                Guid   libraryGuid = (requestGuid == null) ? Guid.Empty : (requestGuid == "") ? Guid.Empty : Guid.Parse(requestGuid);
                if (HttpContext.Request.Form["action"].ToString() == "create")       //insert
                {
                    Item item = new Item();
                    item.LibraryGuid = libraryGuid;
                    item.Deleted     = 0;
                    await _iItem.Add(item);

                    List <DataTableValidateMessage> validate = new List <DataTableValidateMessage>();
                    List <FieldValue> newRecord = new List <FieldValue>();
                    foreach (var key in HttpContext.Request.Form.Keys)
                    {
                        if (key != "action")
                        {
                            string fieldName  = key.Replace("data[0][", "").Replace("]", "");
                            string keyValue   = HttpContext.Request.Form[key].ToString();
                            var    fieldValue = await _iField.FindByNameAndLibraryGuid(fieldName, libraryGuid);

                            FieldValue value = new FieldValue();
                            //value.Field = fieldValue;
                            value.LibraryGuid = libraryGuid;
                            var validation = ValidateForm(fieldValue, HttpContext.Request.Form[key].ToString());
                            if (validation.Status == null)
                            {
                                if (validate.Count == 0)
                                {
                                    value.Item     = item;
                                    value.Value    = keyValue;
                                    value.ItemGuid = item.GUID;
                                    value.Created  = DateTime.Now;
                                    value.FieldID  = fieldValue.ID;
                                    newRecord.Add(value);
                                    //await _iFieldValue.Add(value);
                                }
                            }
                            else
                            {
                                validate.Add(validation);
                            }
                        }
                    }
                    if (validate.Count > 0)
                    {
                        return(new JsonResult(new { fieldErrors = validate }));
                    }
                    else
                    {
                        foreach (var newValue in newRecord)
                        {
                            await _iFieldValue.Add(newValue);
                        }
                        return(new JsonResult(new { result = "New record has been updated." }));
                    }
                }
                else if (HttpContext.Request.Form["action"].ToString() == "edit")//cell update
                {
                    foreach (var key in HttpContext.Request.Form.Keys)
                    {
                        if (key != "action")
                        {
                            string[] keys   = Common.getUpdateKey(key);
                            int      itemID = Convert.ToInt32(keys[0].ToString());
                            var      item   = await _iItem.FindByID(itemID);

                            var filedName  = keys[1].ToString();
                            var fieldValue = await _iFieldValue.FindbyNameAndLibraryGuidAndItemID(filedName, libraryGuid, itemID);

                            if (fieldValue == null) //propably new field just added to to the library, no field record has been added yet. Add new field to library record
                            {
                                var newField = await _iField.FindByNameAndLibraryGuid(filedName, libraryGuid);

                                fieldValue = new FieldValue();
                                //fieldValue.Field = newField;
                                fieldValue.Value = HttpContext.Request.Form[key].ToString();
                                var validation = ValidateForm(newField, HttpContext.Request.Form[key].ToString());
                                if (validation.Status == null)
                                {
                                    fieldValue.Item        = item;
                                    fieldValue.FieldID     = newField.ID;
                                    fieldValue.ItemGuid    = item.GUID;
                                    fieldValue.LibraryGuid = libraryGuid;
                                    fieldValue.Updated     = DateTime.Now;
                                    await _iFieldValue.Add(fieldValue);
                                }
                                else
                                {
                                    return(new JsonResult(new { status = false, result = validation.Status }));
                                }
                            }
                            else
                            {
                                var validation = ValidateForm(fieldValue.Field, HttpContext.Request.Form[key].ToString());
                                if (validation.Status == null)
                                {
                                    fieldValue.Value   = HttpContext.Request.Form[key].ToString();
                                    fieldValue.Updated = DateTime.Now;
                                    await _iFieldValue.Update(fieldValue);
                                }
                                else
                                {
                                    return(new JsonResult(new { status = false, result = validation.Status }));
                                }
                            }
                            return(new JsonResult(new { status = true, value = HttpContext.Request.Form[key].ToString(), result = filedName + " value " + fieldValue.Value + " has been updated" }));
                        }
                    }
                }
                else if (HttpContext.Request.Form["action"].ToString() == "remove")//remove)
                {
                    string[] keys = Common.getUpdateKey(HttpContext.Request.Form.Keys.ToArray()[0]);
                    await _iItem.Delete(Convert.ToInt32(keys[0]));

                    return(new JsonResult(new { result = "Record has been deleted" }));
                }
                return(new JsonResult(new { result = "success" }));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new { result = ex.Message }));
            }
        }
Exemple #6
0
 /// <summary>
 /// Undoes the action.
 /// </summary>
 public void ExecuteUndo()
 {
     _item.Add();
 }
 public void Add(Item objItem)
 {
     Itemobj1.Add(objItem);
 }