Example #1
0
        public string SaveStock(AddExtraStock Model1)
        {
            tbl_KitchenStock tb = new tbl_KitchenStock();
            var duplicate       = _entities.tbl_KitchenStock.Where(o => o.RawMaterialId.Equals(Model1.RawId) && o.Quantity.Equals(Model1.currentstock)).SingleOrDefault();

            if (duplicate == null)
            {
                try
                {
                    if (Model1.RawMaterial != null)
                    {
                        tb          = _entities.tbl_KitchenStock.Where(x => x.RawMaterialId == Model1.RawId).SingleOrDefault();
                        tb.Quantity = Model1.currentstock;
                        _entities.SaveChanges();
                        return("Record Updated Successfully...");
                    }
                    else
                    {
                        tb.Quantity = Model1.currentstock;
                        _entities.tbl_KitchenStock.Add(tb);
                        _entities.SaveChanges();
                        return("Record Saved Successfully...");
                    }
                }
                catch
                {
                    return("something Wrong try Agian !");
                }
            }
            else
            {
                return(Model1.RawId + " Already Exits");
            }
        }
        public ActionResult ExtraStock(AddExtraStock Model1)
        {
            con = new SqlConnection(webconnection);
            StringBuilder sb    = new StringBuilder();
            int           rawid = Convert.ToInt32(Model1.RawMaterial);

            if (Model1.currentstock != null && Model1.currentvalue != null)
            {
                sb.Append("update tbl_KitchenStock set Quantity=" + Model1.currentstock + " where  RawMaterialId=" + Model1.RawMaterial);
                if (db.tblOpStckRates.Where(p => p.MaterialId.Equals(rawid)).Count() > 0)
                {
                    sb.Append(" update tblOpStckRate set Qty= " + Model1.currentstock + ", Rate=" + Model1.currentvalue + " , Date = '" + Model1.stockDate + "' where  MaterialId=" + Model1.RawMaterial);
                }
                else
                {
                    sb.Append(" insert into tblOpStckRate values(" + Model1.RawMaterial + ", " + Model1.currentvalue + " ,'" + Model1.stockDate + "'," + Model1.currentstock + " , 0,0)");
                }
            }



            cmd             = new SqlCommand(sb.ToString(), con);
            cmd.CommandType = CommandType.Text;

            con.Open();
            cmd.ExecuteNonQuery();

            con.Close();

            return(RedirectToAction("CurrentStockReport", "KitchenStock"));
        }