Ejemplo n.º 1
0
        public ServerReturnMessage saveCompartToolImage(CompartToolImageViewModel ImageRecord)
        {
            ServerReturnMessage result = new ServerReturnMessage
            {
                Id      = 0,
                Message = "Compartment is not found!",
                Succeed = false
            };

            if (Id == 0)
            {
                return(result);
            }
            result.Message = "Selected tool is invalid!";
            var tool = _context.TRACK_TOOL.Find(ImageRecord.ToolId);

            if (tool == null)
            {
                return(result);
            }
            COMPART_TOOL_IMAGE ctImage = new COMPART_TOOL_IMAGE();

            ctImage.CompartId   = Id;
            ctImage.ToolId      = ImageRecord.ToolId;
            ctImage.Title       = ImageRecord.Title;
            ctImage.ImageData   = Convert.FromBase64String(ImageRecord.ImageDataBase64);
            ctImage.ImageType   = ImageRecord.ImageType;
            ctImage.CreatedDate = DateTime.Now;
            var k = _context.COMPART_TOOL_IMAGE.Where(m => m.CompartId == ImageRecord.CompartId && m.ToolId == ImageRecord.ToolId);

            if (k.Count() > 0)
            {
                _context.COMPART_TOOL_IMAGE.RemoveRange(k);
            }
            _context.COMPART_TOOL_IMAGE.Add(ctImage);
            try
            {
                _context.SaveChanges();
                result.Succeed = true;
                result.Message = "Operation succeeded";
                return(result);
            }
            catch (Exception e1)
            {
                result.Message          = "Operation failed! please try again!";
                result.ExceptionMessage = e1.Message;
                if (e1.InnerException != null)
                {
                    result.InnerExceptionMessage = e1.InnerException.Message;
                }
                result.Succeed = false;
                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// By using this method parent of the current compart will be set or updated
        /// This method will be used for mining shovel comparts
        /// </summary>
        /// <param name="parentCompartId">Parent Compartment Id to be set for this compartment</param>
        /// <returns></returns>
        public ServerReturnMessage AssignParent(int parentCompartId)
        {
            ServerReturnMessage result = new ServerReturnMessage
            {
                Id      = 0,
                Message = "Compartment is not found!",
                Succeed = false
            };

            if (Id == 0)
            {
                return(result);
            }
            var        thisCompartAschildList = _context.COMPART_PARENT_RELATION.Where(m => m.ChildCompartId == Id);
            LU_COMPART parentCompart          = _context.LU_COMPART.Find(parentCompartId);

            if (thisCompartAschildList.Count() > 0) //Update or Remove
            {
                COMPART_PARENT_RELATION relationRecord = thisCompartAschildList.First();
                if (parentCompartId == 0) //Remove
                {
                    _context.COMPART_PARENT_RELATION.Remove(relationRecord);
                }
                else if (parentCompart != null) //Update
                {
                    relationRecord.ParentCompartId       = parentCompart.compartid_auto;
                    _context.Entry(relationRecord).State = EntityState.Modified;
                }
                else //Not remove and not able to update because parent compart not found
                {
                    result.Succeed = true;
                    result.Message = "Operation partially successful! Parent compart not found to be updated";
                    return(result);
                }
            }
            else if (parentCompart != null) //Add
            {
                _context.COMPART_PARENT_RELATION.Add(
                    new COMPART_PARENT_RELATION {
                    ChildCompartId = Id, ParentCompartId = parentCompartId
                }
                    );
            } // Not a change or not an update. Just doing nothing about parent
            else
            {
                result.Succeed = true;
                result.Message = "Operation was successful! No parent assigned or updated for this component.";
                return(result);
            }
            try
            {
                _context.SaveChanges();
                result.Succeed = true;
                result.Message = "Operation was successful!";
                return(result);
            }
            catch (Exception e1)
            {
                result.Message          = "Operation failed! please try again!";
                result.ExceptionMessage = e1.Message;
                if (e1.InnerException != null)
                {
                    result.InnerExceptionMessage = e1.InnerException.Message;
                }
                result.Succeed = false;
                return(result);
            }
        }