예제 #1
0
        public LoginDTO DoRegister(LoginDTO item)
        {
            LoginDTO    dto     = new LoginDTO();
            UserProfile profile = new UserProfile();

            profile.Admin    = item.IsAdmin;
            profile.Password = item.Password;
            profile.UserId   = item.UserId;

            using (var context = new WebParser.DAL.DataModel.WebParserEntities())
            {
                bool isUserIDExist = context.UserProfiles.Any(c => c.UserId == profile.UserId);
                if (isUserIDExist)
                {
                    return(null);
                }
                else
                {
                    context.UserProfiles.Add(profile);
                    int value = context.SaveChanges();
                    dto = context.UserProfiles.Where(c => c.UserId == profile.UserId && c.Password == profile.Password).Select(v => new LoginDTO()
                    {
                        IsAdmin = v.Admin,
                        UserId  = v.UserId,
                    }).FirstOrDefault();
                }
            }
            return(dto);
        }
        public ReturnResultDTO ImportXmlData(List <ImportXMLDataDTO> inputDTOList)
        {
            int             scanId    = 0;
            int             subScnaID = 0;
            ReturnResultDTO dtoItem;

            if (inputDTOList.Any(c => c.IsAdditionalScan))
            {
                //Generate New ScanID;
                scanId    = inputDTOList.First().ScanId;
                subScnaID = inputDTOList.First().SubScanId + 1;
            }

            //Create MasterScan
            ScanMaster master = CreateScanMaster(scanId, subScnaID, inputDTOList.First().UserId, inputDTOList.First().ClientName, inputDTOList.First().ScanDate, inputDTOList.First().ScanName);


            using (var context = new WebParser.DAL.DataModel.WebParserEntities())
            {
                if (!inputDTOList.Any(c => c.IsAdditionalScan))
                {
                    ScanNumber newNumber = new ScanNumber()
                    {
                        UserId = inputDTOList.First().UserId
                    };
                    context.ScanNumbers.Add(newNumber);
                    context.SaveChanges();

                    var userID     = inputDTOList.First().UserId;
                    var listOfScan = context.ScanNumbers.Where(c => c.UserId == userID).ToList();
                    scanId        = listOfScan.Last().ScanId;
                    master.ScanId = scanId;
                }
                foreach (var item in inputDTOList)
                {
                    CurrScan newItem = CreateCurrentScan(item, scanId, subScnaID);
                    master.CurrScans.Add(newItem);
                    //context.CurrScans.Add(newItem);
                }
                context.ScanMasters.Add(master);
                int value = 0;
                try
                {
                    using (TransactionScope trans = new TransactionScope())
                    {
                        value = context.SaveChanges();
                        if (value > 0)
                        {
                            dtoItem           = CheckExistingData(scanId);
                            dtoItem.IsSuccess = true;
                            trans.Complete();
                        }
                        else
                        {
                            dtoItem           = new ReturnResultDTO();
                            dtoItem.IsSuccess = false;
                            trans.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(dtoItem);
        }