public MaterialMasterDTO Update(MaterialMasterDTO obj)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    MaterialMaster tempObj = (from r in _unitOfWork.MaterialMaster.GenerateEntityAsIQueryable()
                                              where r.SPEC_NO == obj.SPEC_NO && r.ID != obj.ID
                                              select r).FirstOrDefault();

                    if (tempObj == null)
                    {
                        var response = _unitOfWork.MaterialMaster.FindById(obj.ID);
                        if (response != null)
                        {
                            response.NOMINAL_COMPOSITION = obj.NOMINAL_COMPOSITION;
                            response.PRODUCT_FORM        = obj.PRODUCT_FORM;
                            response.CreatedBy           = obj.CreatedBy;
                            response.CreatedDate         = obj.CreatedDate;
                            response.ModifiedBy          = obj.ModifiedBy;
                            response.ModifiedDate        = DateTime.Now;
                        }
                        _unitOfWork.MaterialMaster.Update(response);
                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new MaterialMasterDTO
                        {
                            ID = obj.ID,
                            Status = true,
                            StatusMessage = "Successfully updated",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new MaterialMasterDTO
                        {
                            ID = tempObj.ID,
                            Status = false,
                            StatusMessage = "Error - Duplicate Material.",
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new MaterialMasterDTO()
                    {
                        ID = 0,
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }
        public MaterialMasterDTO Create(MaterialMasterDTO obj)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    MaterialMaster tempObj = (from i in _unitOfWork.MaterialMaster.GenerateEntityAsIQueryable()
                                              where i.SPEC_NO == obj.SPEC_NO
                                              select i).FirstOrDefault();

                    if (tempObj == null)
                    {
                        var materialMaster = new MaterialMaster()
                        {
                            SPEC_NO     = obj.SPEC_NO,
                            TYPE_GRADE  = obj.TYPE_GRADE,
                            CreatedBy   = obj.CreatedBy,
                            CreatedDate = DateTime.Now
                        };

                        _unitOfWork.MaterialMaster.Create(materialMaster);
                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new MaterialMasterDTO
                        {
                            ID = materialMaster.ID,
                            Status = true,
                            StatusMessage = "Successfully created",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new MaterialMasterDTO
                        {
                            ID = tempObj.ID,
                            Status = false,
                            StatusMessage = "Error - Duplicate Matrial - " + tempObj.SPEC_NO,
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new MaterialMasterDTO()
                    {
                        ID = 0,
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }
 public MaterialMasterDTO Put([FromBody] MaterialMasterDTO MaterialMasterDTO)
 {
     return(_MaterialMasterService.Update(MaterialMasterDTO));
 }
 public MaterialMasterDTO Post([FromBody] MaterialMasterDTO MaterialMasterDTO)
 {
     return(_MaterialMasterService.Create(MaterialMasterDTO));
 }