示例#1
0
        public Result UpsertItem(ItemDto itemDto)
        {
            try
            {
                if (itemDto.Mode == EnumCrudMode.Create)
                {
                    ItemRepo.AddItem(itemDto);
                }
                else if (itemDto.Mode == EnumCrudMode.Update)
                {
                    ItemRepo.UpdateItem(itemDto);
                }
                else if (itemDto.Mode == EnumCrudMode.Delete)
                {
                    ItemRepo.DeleteItem(itemDto);
                }

                return(new Result()
                {
                    ResultCode = EnumResultCode.OK, Dto = itemDto
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    ResultCode = EnumResultCode.Error, Details = ex.Message, Dto = itemDto
                });
            }
        }
示例#2
0
        public bool UpdateItems(Item i)
        {
            _i = i;

            ItemRepo repo = new ItemRepo();

            return(repo.UpdateItem(_i));
        }
        public IHttpActionResult UpdateItem(ItemModel item)
        {
            string    error = "";
            ItemModel im    = ItemRepo.UpdateItem(item, out error);

            if (error != "" || im == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "Item Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(im));
        }
示例#4
0
        public ActionResult EditItem(ItemVM item)
        {
            bool ItemUpdated;

            if (ModelState.IsValid)
            {
                ItemRepo itemRepo = new ItemRepo();
                ItemUpdated = itemRepo.UpdateItem(item);
                if (ItemUpdated)
                {
                    return(RedirectToAction("ItemDetail", new { id = item.ItemID }));
                }
                else
                {
                    ViewBag.ErrorMsg = "Updated failed";
                }
            }
            ItemRepo itemRepo2 = new ItemRepo();
            ItemVM   item2     = itemRepo2.GetDetails(item.ItemID);

            ViewBag.Categories = new SelectList(GetCategories(), "Value",
                                                "Text", item.ItemID);
            return(View(item2));
        }
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            if (request.Resource.Contains("item"))
            {
                if (request.HttpMethod == "POST" && request.QueryStringParameters.ContainsKey("tableName"))
                {
                    var obj      = JsonConvert.DeserializeObject(request.Body);
                    var data     = JObject.FromObject(obj);
                    var itemRepo = new ItemRepo(new AmazonDynamoDBClient());
                    try{
                        await itemRepo.AddNewItem(request.QueryStringParameters["tableName"], (JArray)data["item"]);

                        return(new APIGatewayProxyResponse {
                            StatusCode = 200
                        });
                    }catch {}
                }
                else if (request.HttpMethod == "PUT" && request.QueryStringParameters.ContainsKey("tableName"))
                {
                    var obj      = JsonConvert.DeserializeObject(request.Body);
                    var data     = JObject.FromObject(obj);
                    var itemRepo = new ItemRepo(new AmazonDynamoDBClient());
                    try{
                        await itemRepo.UpdateItem(request.QueryStringParameters["tableName"], (JArray)data["item"]);

                        return(new APIGatewayProxyResponse {
                            StatusCode = 200
                        });
                    }catch {}
                }
                else if (request.HttpMethod == "DELETE" && request.QueryStringParameters.ContainsKey("tableName"))
                {
                    var itemRepo = new ItemRepo(new AmazonDynamoDBClient());
                    try{
                        if (request.QueryStringParameters.ContainsKey("rangeKey"))
                        {
                            await itemRepo.RemoveItem(request.QueryStringParameters["tableName"], request.QueryStringParameters["hashKey"], request.QueryStringParameters["rangeKey"]);
                        }
                        else
                        {
                            await itemRepo.RemoveItem(request.QueryStringParameters["tableName"], request.QueryStringParameters["hashKey"], null);
                        }
                        return(await Task.FromResult(new APIGatewayProxyResponse {
                            StatusCode = 200
                        }));
                    }catch {}
                }
                else if (request.HttpMethod == "GET" && request.QueryStringParameters.ContainsKey("tableName") && request.QueryStringParameters.ContainsKey("hashKey"))
                {
                    var itemRepo = new ItemRepo(new AmazonDynamoDBClient());
                    var item     = new Document();
                    if (request.QueryStringParameters.ContainsKey("rangeKey") is true)
                    {
                        item = await itemRepo.GetItem(request.QueryStringParameters["tableName"], request.QueryStringParameters["hashKey"], request.QueryStringParameters["rangeKey"]);
                    }
                    else
                    {
                        item = await itemRepo.GetItem(request.QueryStringParameters["tableName"], request.QueryStringParameters["hashKey"], null);
                    }
                    return(new APIGatewayProxyResponse {
                        StatusCode = 200,
                        Body = JsonConvert.SerializeObject(item)
                    });
                }
                return(await Task.FromResult(new APIGatewayProxyResponse {
                    StatusCode = 404
                }));
            }
            if (request.HttpMethod == "GET" && request.Resource.Contains("getattr"))
            {
                var tableRepo = new TableRepo(new AmazonDynamoDBClient());
                var attr      = await tableRepo.GetTableAttr(request.QueryStringParameters["tableName"]);

                return(new APIGatewayProxyResponse {
                    StatusCode = 200,
                    Body = JsonConvert.SerializeObject(attr)
                });
            }
            else if (request.HttpMethod == "GET" && request.Resource.Contains("gettable"))
            {
                var itemRepo = new ItemRepo(new AmazonDynamoDBClient());
                var table    = await itemRepo.GetItems(request.QueryStringParameters["tableName"]);

                return(new APIGatewayProxyResponse {
                    StatusCode = 200,
                    Body = JsonConvert.SerializeObject(table)
                });
            }
            else if (request.HttpMethod == "GET")
            {
                var tableRepo = new TableRepo(new AmazonDynamoDBClient());
                var tables    = await tableRepo.GetTablesAsync();

                return(new APIGatewayProxyResponse {
                    StatusCode = 200,
                    Body = JsonConvert.SerializeObject(tables)
                });
            }
            else if (request.HttpMethod == "POST")
            {
                var table = JsonConvert.DeserializeObject <Dtos.CreateTableDto>(request.Body);
                if (table == null)
                {
                    return new APIGatewayProxyResponse {
                               StatusCode = 400
                    }
                }
                ;

                var tableRepo = new TableRepo(new AmazonDynamoDBClient());
                if (await tableRepo.CreateTableAsync(table))
                {
                    return(new APIGatewayProxyResponse {
                        StatusCode = 200, Body = "OK"
                    });
                }
                else
                {
                    return(new APIGatewayProxyResponse {
                        StatusCode = 400
                    });
                }
            }
            else if (request.HttpMethod == "DELETE")
            {
                if (request.QueryStringParameters.ContainsKey("tableName"))
                {
                    var tableName = request.QueryStringParameters["tableName"];
                    var tableRepo = new TableRepo(new AmazonDynamoDBClient());
                    if (await tableRepo.RemoveTableAsync(tableName))
                    {
                        return(new APIGatewayProxyResponse {
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new APIGatewayProxyResponse {
                            StatusCode = 400
                        });
                    }
                }
                return(new APIGatewayProxyResponse {
                    StatusCode = 400
                });
            }

            return(await Task.FromResult(new APIGatewayProxyResponse {
                StatusCode = 404
            }));
        }
    }
示例#6
0
        public ActionResult Edit(int id, FormCollection frm, string[] hddrowpindex)
        {
            var ses   = sesrepo.GetSessionById((User as CustomPrincipal).UserId);
            int orgid = ses.OrganizationId;

            try
            {
                MS_Item item = db.GetItemById(id);// (Convert.ToInt32(frm["ItemId"]));
                item.ItemName = frm["ItemName"];
                //item.ItemCode = frm["ItemCode"];
                //item.ItemDescription = frm["ItemDescription"];
                item.OrganizationId  = orgid;// Convert.ToInt32(frm["OrganizationId"]);
                item.CategoryId      = Convert.ToInt32(frm["CategoryId"]);
                item.LastUpdatedBy   = (User as CustomPrincipal).UserId;
                item.LastUpdatedDate = DateTime.Now;
                db.UpdateItem(item);
                iu.DeleteAllItemUnitByItem(item.ItemId, 0, DateTime.Now);
                MS_ItemUnit uitem;
                if (hddrowpindex != null && hddrowpindex.Count() > 0)
                {
                    foreach (var unititem in hddrowpindex)
                    {
                        if (frm["ItemUnitId-" + unititem] != "0")
                        {
                            uitem = iu.GetItemUnitById(Convert.ToInt32(frm["ItemUnitId-" + unititem]));
                        }
                        else
                        {
                            uitem = new MS_ItemUnit();
                        }
                        uitem.UnitId           = Convert.ToInt32(frm["UnitId-" + unititem]);
                        uitem.UnitSellingPrice = Convert.ToDecimal(frm["SellingPrice-" + unititem]);
                        uitem.QuantityInPiece  = Convert.ToInt32(frm["QuantityPer-" + unititem]);
                        if (frm["IsDefault-" + unititem] != null)
                        {
                            uitem.IsDefault = true;
                        }
                        else
                        {
                            uitem.IsDefault = false;
                        }
                        uitem.OrganizationId = item.OrganizationId;
                        uitem.ItemId         = item.ItemId;
                        if (frm["ItemUnitId-" + unititem] != "0")
                        {
                            iu.UpdateItemUnit(uitem);
                        }
                        else
                        {
                            iu.InsertItemUnit(uitem);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //ViewBag.UnitList = udb.GetUnitList(0, "", "");
                //ViewBag.CategoryId = new SelectList(ddl.GetCategoryList(), "Id", "Name", frm["CategoryId"]);
                //ViewBag.OrganizationId = new SelectList(ddl.GetOrganizationList(), "Id", "Name", frm["OrganizationId"]);

                return(RedirectToAction("Edit", new { id = frm["ItemId"] }));
            }
            //ViewBag.UnitList = udb.GetUnitList(0, "", "");
            //ViewBag.CategoryId = new SelectList(ddl.GetCategoryList(), "Id", "Name", frm["CategoryId"]);
            //ViewBag.OrganizationId = new SelectList(ddl.GetOrganizationList(), "Id", "Name", frm["OrganizationId"]);
            return(RedirectToAction("Index"));
        }