Esempio n. 1
0
        public StructuralMinThkDTO Create(StructuralMinThkDTO structuralMinThkDTO)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    StructuralMinThk tempObj = (from s in _unitOfWork.StructuralMinThk.GenerateEntityAsIQueryable()
                                                where s.ComponentType == structuralMinThkDTO.ComponentType
                                                select s).FirstOrDefault();

                    if (tempObj == null)
                    {
                        var obj = new StructuralMinThk()
                        {
                            ComponentType            = structuralMinThkDTO.ComponentType,
                            OutsideDiameterInches    = structuralMinThkDTO.OutsideDiameterInches,
                            OutsideDiameterMM        = structuralMinThkDTO.OutsideDiameterMM,
                            StructureWallThicknessMM = structuralMinThkDTO.StructureWallThicknessMM,
                            Active      = true,
                            CreatedBy   = structuralMinThkDTO.CreatedBy,
                            CreatedDate = DateTime.Now
                        };

                        _unitOfWork.StructuralMinThk.Create(obj);
                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new StructuralMinThkDTO
                        {
                            ID = obj.ID,
                            Status = true,
                            StatusMessage = "Successfully created",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new StructuralMinThkDTO
                        {
                            ID = tempObj.ID,
                            Status = false,
                            StatusMessage = "Error - Duplicate Component Type - " + tempObj.ComponentType,
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new StructuralMinThkDTO()
                    {
                        ID = 0,
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }
Esempio n. 2
0
        public StructuralMinThkDTO Update(StructuralMinThkDTO structuralMinThkDTO)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    StructuralMinThk tempObj = (from r in _unitOfWork.StructuralMinThk.GenerateEntityAsIQueryable()
                                                where r.ComponentType == structuralMinThkDTO.ComponentType && r.ID != structuralMinThkDTO.ID
                                                select r).FirstOrDefault();

                    if (tempObj == null)
                    {
                        var response = _unitOfWork.StructuralMinThk.FindById(structuralMinThkDTO.ID);
                        if (response != null)
                        {
                            response.ComponentType            = structuralMinThkDTO.ComponentType;
                            response.OutsideDiameterInches    = structuralMinThkDTO.OutsideDiameterInches;
                            response.OutsideDiameterMM        = structuralMinThkDTO.OutsideDiameterMM;
                            response.StructureWallThicknessMM = structuralMinThkDTO.StructureWallThicknessMM;

                            response.Active       = structuralMinThkDTO.Active;
                            response.CreatedBy    = structuralMinThkDTO.CreatedBy;
                            response.CreatedDate  = structuralMinThkDTO.CreatedDate;
                            response.ModifiedBy   = structuralMinThkDTO.ModifiedBy;
                            response.ModifiedDate = DateTime.Now;
                        }
                        _unitOfWork.StructuralMinThk.Update(response);
                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new StructuralMinThkDTO
                        {
                            ID = structuralMinThkDTO.ID,
                            Status = true,
                            StatusMessage = "Successfully updated",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new StructuralMinThkDTO
                        {
                            ID = tempObj.ID,
                            Status = false,
                            StatusMessage = "Error - Duplicate Component Type.",
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new StructuralMinThkDTO()
                    {
                        ID = 0,
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }