예제 #1
0
        public TerminalResponse UploadBulkTerminalRecords(List <TerminalBulkRequest> param)
        {
            int successful = 0;
            int failed     = 0;
            int existing   = 0;

            try
            {
                foreach (var n in param)
                {
                    var existTerminal = GetTerminalDetailsByNo(n.TerminalNo);
                    if (existTerminal == null)
                    {
                        var value = new TerminalRequest();
                        value.TerminalNo       = n.TerminalNo;
                        value.TerminalRef      = n.TerminalRef;
                        value.SerialNo         = n.SerialNo;
                        value.BrandId          = _brand.GetBrandByName(n.BrandName).Brandid;
                        value.ClientId         = _client.GetClientByName(n.ClientName).Clientid;
                        value.Engineer         = _user.GetUserByEmail(n.Engineer).Username;
                        value.IsUnderSupport   = SupportStatus(n.Support.ToUpper());
                        value.IsTerminalActive = value.IsUnderSupport;
                        value.TerminalAlias    = n.TerminalAlias;
                        value.StateId          = GetStateByName(n.State.ToLower()).StateId;
                        value.Location         = n.Location;
                        value.CreatedBy        = n.CreatedBy;
                        value.CreatedOn        = n.CreatedOn;
                        InsertTerminal(value);
                        successful++;
                    }
                    else
                    {
                        existing++;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.InfoFormat(param.FirstOrDefault().Computername, param.FirstOrDefault().SystemIp, param.FirstOrDefault().CreatedBy, Constants.ActionType.SetUpTerminal.ToString());
                return(new TerminalResponse
                {
                    ResponseCode = "01",
                    ResponseMessage = ex.Message + " " + successful + " was added successfully",
                    TerminalDetails = new List <TerminalDetailsObj>()
                });
            }

            Log.InfoFormat(param.FirstOrDefault().Computername, param.FirstOrDefault().SystemIp, param.FirstOrDefault().CreatedBy, Constants.ActionType.SetUpTerminal.ToString());
            _audit.InsertAudit(param.FirstOrDefault().CreatedBy, Constants.ActionType.SetUpTerminal.ToString(), "Create terminal", DateTime.Now, param.FirstOrDefault().Computername, param.FirstOrDefault().SystemIp);
            return(new TerminalResponse
            {
                ResponseCode = "00",
                ResponseMessage = successful + " Record successfully added, " + failed + " failed and " + existing + " already exists",
                TerminalDetails = new List <TerminalDetailsObj>()
            });
        }