Esempio n. 1
0
        public List <delRes> deleteUser([FromBody] delParam info)
        {
            var model = new BorgWarnerMisSQLContext();

            var testData = model.Database.SqlQuery <delRes>($"EXECUTE dbo.QforDeleteUser @username='******',@token='{info.token}' ").ToList();

            return(testData);
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Delete([FromBody] delParam param)
        {
            try
            {
                db0 = getDB0();
                r   = new ResultInfo <Product>();

                item = await db0.Product.FindAsync(param.id);

                if (db0.PurchaseDetail.Any(x => x.product_id == item.product_id))
                {
                    r.result  = false;
                    r.message = Resources.Res.Log_Err_Delete_Used;
                    return(Ok(r));
                }

                if (item != null)
                {
                    db0.Product.Remove(item);
                    db0.ProductDetail.RemoveRange(item.ProductDetail);
                    await db0.SaveChangesAsync();

                    r.result = true;
                    return(Ok(r));
                }
                else
                {
                    r.result  = false;
                    r.message = Resources.Res.Log_Err_Delete_NotFind;
                    return(Ok(r));
                }
            }
            catch (DbUpdateException ex)
            {
                r.result = false;
                if (ex.InnerException != null)
                {
                    r.message = Resources.Res.Log_Err_Delete_DetailExist + "\r\n" + getErrorMessage(ex);
                }
                else
                {
                    r.message = ex.Message;
                }
                return(Ok(r));
            }
            catch (Exception ex)
            {
                r.result  = false;
                r.message = ex.Message;
                return(Ok(r));
            }
            finally
            {
                db0.Dispose();
            }
        }