Example #1
0
        public async Task <IActionResult> Edit([Bind("RawMatTypeCode,RawMatTypeName,RawMatTypeDesc,CompanyCode,Id,Is_Active,Created_Date,Created_By,Updated_Date,Updated_By")] M_RawMaterialType m_RawMaterialType)
        {
            if (ModelState.IsValid)
            {
                m_RawMaterialType.Updated_By = await base.CurrentUserId();

                ResultObject resultObj;

                try
                {
                    using (var rawMatTypeBll = new RawMaterialTypeBLL())
                    {
                        resultObj = await rawMatTypeBll.UpdateRawMaterialType(m_RawMaterialType);

                        _cache.Remove("CACHE_MASTER_RAWMATTYPE");
                    }

                    return(Json(new { success = true, data = (M_RawMaterialType)resultObj.ObjectValue, message = "Raw Mat. Type Update." }));
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, data = m_RawMaterialType, message = ex.Message }));
                }
            }

            var err = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList();

            return(Json(new { success = false, errors = err, data = m_RawMaterialType, message = "Update Failed" }));
        }
Example #2
0
        public async Task <ResultObject> DeleteRawMaterialType(M_RawMaterialType rawmatType)
        {
            var resultObj = new ResultObject {
                RowAffected = -1, ObjectValue = rawmatType
            };

            using (var context = new MasterDbContext(contextOptions))
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        MySqlParameter[] sqlParams = new MySqlParameter[] {
                            new MySqlParameter("strId", rawmatType.Id),
                            new MySqlParameter("strDelete_By", rawmatType.Updated_By)
                        };


                        //Output Parameter no need to define. @`strId`
                        resultObj.RowAffected = await context.Database.ExecuteSqlCommandAsync("call sp_rawmaterialtype_delete( ?, ?)", parameters : sqlParams);

                        transaction.Commit();

                        return(resultObj);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Example #3
0
        public async Task <ResultObject> InsertRawMaterialType(M_RawMaterialType rawmatType)
        {
            var resultObj = new ResultObject {
                RowAffected = -1, ObjectValue = rawmatType
            };

            using (var context = new MasterDbContext(contextOptions))
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        MySqlParameter[] sqlParams = new MySqlParameter[] {
                            new MySqlParameter("strRawMatTypeCode", rawmatType.RawMatTypeCode),
                            new MySqlParameter("strRawMatTypeName", rawmatType.RawMatTypeName),
                            new MySqlParameter("strRawMatTypeDesc", rawmatType.RawMatTypeDesc),
                            new MySqlParameter("strCompanyCode", rawmatType.CompanyCode),
                            new MySqlParameter("strIs_Active", rawmatType.Is_Active),
                            new MySqlParameter("strCreated_By", rawmatType.Created_By)
                        };

                        resultObj.RowAffected = await context.Database.ExecuteSqlCommandAsync("call sp_rawmaterialtype_insert(@`strId`, ?, ?, ?, ?, ?, ?)", parameters : sqlParams);

                        //new department after insert.
                        var newDept = context.RawMaterialType.FromSql("SELECT * FROM m_rawmaterialtype WHERE Id = @`strId`;").ToListAsync();
                        resultObj.ObjectValue = newDept.Result[0];

                        transaction.Commit();

                        return(resultObj);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Example #4
0
        public async Task <ResultObject> UpdateRawMaterialType(M_RawMaterialType rawmatType)
        {
            var resultObj = new ResultObject {
                RowAffected = -1, ObjectValue = rawmatType
            };

            using (var context = new MasterDbContext(contextOptions))
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.Entry(rawmatType).State = EntityState.Modified;

                        MySqlParameter[] sqlParams = new MySqlParameter[] {
                            new MySqlParameter("strId", rawmatType.Id),
                            new MySqlParameter("strRawMatTypeCode", rawmatType.RawMatTypeCode),
                            new MySqlParameter("strRawMatTypeName", rawmatType.RawMatTypeName),
                            new MySqlParameter("strRawMatTypeDesc", rawmatType.RawMatTypeDesc),
                            new MySqlParameter("strCompanyCode", rawmatType.CompanyCode),
                            new MySqlParameter("strIs_Active", rawmatType.Is_Active),
                            new MySqlParameter("strCreated_By", rawmatType.Updated_By)
                        };

                        //Output Parameter no need to define. @`strId`
                        resultObj.RowAffected = await context.Database.ExecuteSqlCommandAsync("call sp_rawmaterialtype_update(?, ?, ?, ?, ?, ?, ?)", parameters : sqlParams);

                        transaction.Commit();

                        return(resultObj);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }