public async Task <IActionResult> AddAndUpdateMachineMaster(AddUpdateMachine data) { CommonResponse response = machineMaster.AddAndUpdateMachineMaster(data); return(Ok(response)); }
/// <summary> /// Add And Update Machine Master /// </summary> /// <param name="data"></param> /// <returns></returns> public CommonResponse AddAndUpdateMachineMaster(AddUpdateMachine data) { CommonResponse obj = new CommonResponse(); try { var check = db.UnitworkccsTblmachinedetails.Where(m => m.MachineId == data.machineId).FirstOrDefault(); if (check == null) { try { UnitworkccsTblmachinedetails tblmachinedetails = new UnitworkccsTblmachinedetails(); tblmachinedetails.PlantId = data.plantId; tblmachinedetails.ShopId = data.shopId; tblmachinedetails.CellId = data.cellId; tblmachinedetails.Ipaddress = data.ipAddress; tblmachinedetails.MachineName = data.machineNo; tblmachinedetails.MachineDisplayName = data.machineNo; tblmachinedetails.MachinePockets = Convert.ToInt32(data.noOfToolStation); tblmachinedetails.Mmmgroup = data.mmmGroup; tblmachinedetails.MachineDescription = data.machineName; tblmachinedetails.DedicatedOrShared = data.dedicatedOrShared; tblmachinedetails.PrimaryOrSecondary = data.primaryOrSecondary; tblmachinedetails.MachineCategoryId = data.machineCategoryId; tblmachinedetails.MachineMake = Convert.ToString(data.makeId); tblmachinedetails.MachineSpec = data.machineSpec; tblmachinedetails.ChuckOrRodSize = Convert.ToInt32(data.chuckOrRodSize); tblmachinedetails.TallStockAvailId = Convert.ToInt32(data.tallStockAvailibilityId); tblmachinedetails.NoOfAxisId = Convert.ToInt32(data.noOfAxisId); tblmachinedetails.TableSize = data.tableSize; tblmachinedetails.PalletId = Convert.ToInt32(data.palletId); tblmachinedetails.Category = data.criticalOrNonCritical; if (data.machineBelongTo == "Wimarasys") { tblmachinedetails.IsWimerasys = 1; tblmachinedetails.MachineModelType = 99; } else { if (data.controllerType == "FANUC") { tblmachinedetails.ControllerType = "FANUC"; tblmachinedetails.MachineModelType = 1; } else if (data.controllerType == "DL") { tblmachinedetails.ControllerType = "DL"; tblmachinedetails.IsPcb = 1; tblmachinedetails.MachineModelType = 4; } } tblmachinedetails.IsNormalWc = 0; tblmachinedetails.CreatedOn = DateTime.Now; tblmachinedetails.InsertedOn = Convert.ToString(DateTime.Now); tblmachinedetails.InsertedBy = 1; tblmachinedetails.EnableLockLogic = 0; tblmachinedetails.ServerTabFlagSync = 0; tblmachinedetails.ServerTabCheck = 0; tblmachinedetails.IsShiftWise = 0; tblmachinedetails.IsDeleted = 0; tblmachinedetails.IsDlversion = 0; db.UnitworkccsTblmachinedetails.Add(tblmachinedetails); db.SaveChanges(); obj.isStatus = true; obj.response = ResourceResponse.AddedSuccessMessage; } catch (Exception e) { log.Error(e); if (e.InnerException != null) { log.Error(e.InnerException.ToString()); } obj.isStatus = false; obj.response = ResourceResponse.FailureMessage; } } else { check.PlantId = data.plantId; check.ShopId = Convert.ToInt32(data.shopId); check.CellId = Convert.ToInt32(data.cellId); check.Ipaddress = data.ipAddress; check.MachineName = data.machineNo; check.MachineDisplayName = data.machineName; check.MachinePockets = Convert.ToInt32(data.noOfToolStation); check.Mmmgroup = data.mmmGroup; check.MachineDescription = data.machineName; check.DedicatedOrShared = data.dedicatedOrShared; check.PrimaryOrSecondary = data.primaryOrSecondary; check.MachineCategoryId = data.machineCategoryId; check.MachineMake = Convert.ToString(data.makeId); check.MachineSpec = data.machineSpec; check.ChuckOrRodSize = Convert.ToInt32(data.chuckOrRodSize); check.TallStockAvailId = Convert.ToInt32(data.tallStockAvailibilityId); check.NoOfAxisId = Convert.ToInt32(data.noOfAxisId); check.TableSize = data.tableSize; check.PalletId = Convert.ToInt32(data.palletId); check.Category = data.criticalOrNonCritical; if (data.machineBelongTo == "Wimarasys") { check.IsWimerasys = 1; check.MachineModelType = 99; } else { if (data.controllerType == "FANUC") { check.ControllerType = "FANUC"; check.MachineModelType = 1; } else if (data.controllerType == "DL") { check.ControllerType = "DL"; check.IsPcb = 1; check.MachineModelType = 4; } } check.IsNormalWc = 0; check.CreatedOn = DateTime.Now; check.InsertedOn = Convert.ToString(DateTime.Now); check.InsertedBy = 1; check.EnableLockLogic = 0; check.ServerTabFlagSync = 0; check.ServerTabCheck = 0; check.IsShiftWise = 0; check.IsDeleted = 0; check.IsDlversion = 0; db.SaveChanges(); obj.isStatus = true; obj.response = ResourceResponse.UpdatedSuccessMessage; } } catch (Exception e) { log.Error(e); if (e.InnerException != null) { log.Error(e.InnerException.ToString()); } obj.isStatus = false; obj.response = ResourceResponse.FailureMessage; } return(obj); }