public int Save(Entity.Company Company)
        {
            Query = "INSERT INTO COMPANY (Name) VALUES('" + Company.Name + "')";

            Command = new SqlCommand(Query, Connection);

            Connection.Open();
            var rowAffected = Command.ExecuteNonQuery();

            Connection.Close();

            return(rowAffected);
        }
        public ActionResult Create([Bind(Include = "CustomerId,TrebId,WebsiteUrl,ApplicationID,Password,CompanyID,UserId,PhotoPath,FirstName,LastName,MiddleName,EmailID,MobileNo,CountryID,StateID,CityID,ZipCode,Latitude,Longitude,CreatedOn,LastUpdatedOn,MobileVerifyCode,EmailVerifyCode,IsMobileVerified,IsEmailVerified,IsActive,AdminCompanyAddress")] AdminModel AdminModel, HttpPostedFileBase file, HttpPostedFileBase Logo)
        {
            TempData["ShowMessage"] = "";
            TempData["MessageBody"] = "";
            UserPermissionAction("admin", RoleAction.create.ToString());
            CheckPermission();
            Mapper.CreateMap <CommunicationApp.Models.AdminModel, CommunicationApp.Entity.Customer>();
            CommunicationApp.Entity.Customer Customer = Mapper.Map <CommunicationApp.Models.AdminModel, CommunicationApp.Entity.Customer>(AdminModel);

            if (ModelState.IsValid)
            {
                var customerFound = _CustomerService.GetCustomers().Where(x => x.EmailId == Customer.EmailId || x.MobileNo == Customer.MobileNo || x.WebsiteUrl == Customer.WebsiteUrl).FirstOrDefault();
                if (customerFound == null)
                {
                    //Save Company of admin

                    Company Company = new Entity.Company();
                    Company.WebSite        = Customer.WebsiteUrl;
                    Company.CountryID      = 1;
                    Company.StateID        = 1;
                    Company.CityID         = 1;
                    Company.CompanyAddress = AdminModel.AdminCompanyAddress != "" ? AdminModel.AdminCompanyAddress : "*****@*****.**";
                    Company.CompanyName    = AdminModel.CompanyName != null ? AdminModel.CompanyName : "Company";
                    Company.EmailID        = "*****@*****.**";
                    Company.PhoneNo        = "123456987";
                    Company.IsActive       = true;
                    if (Logo != null)
                    {
                        Company.LogoPath = Savefile(Logo);
                    }

                    _CompanyService.InsertCompany(Company);

                    //Insert User first
                    CommunicationApp.Entity.User user = new CommunicationApp.Entity.User();
                    //user.UserId =0; //New Case
                    user.FirstName        = Customer.FirstName;
                    user.TrebId           = Customer.TrebId;
                    user.LastName         = Customer.LastName;
                    user.UserName         = Customer.EmailId;
                    user.Password         = SecurityFunction.EncryptString(AdminModel.Password);
                    user.UserEmailAddress = Customer.EmailId;
                    user.CompanyID        = Company.CompanyID;
                    user.CreatedOn        = DateTime.Now;
                    user.LastUpdatedOn    = DateTime.Now;
                    user.TrebId           = "0000000";
                    user.IsActive         = true;
                    _UserService.InsertUser(user);
                    //End : Insert User first

                    var UserID = user.UserId;
                    if (user.UserId > 0)
                    {
                        //Insert User Role
                        CommunicationApp.Entity.UserRole userRole = new CommunicationApp.Entity.UserRole();
                        userRole.UserId = user.UserId;
                        userRole.RoleId = 2; //By Default set new Admin/user role id=2
                        _UserRoleService.InsertUserRole(userRole);
                        //End : Insert User Role

                        //Insert the Customer
                        Customer.FirstName        = Customer.FirstName;
                        Customer.UserId           = user.UserId;
                        Customer.Designation      = "Admin";
                        Customer.MobileVerifyCode = CommonCls.GetNumericCode();
                        Customer.EmailVerifyCode  = CommonCls.GetNumericCode();
                        Customer.MobileVerifyCode = "9999";
                        Customer.EmailVerifyCode  = "9999";
                        Customer.CreatedOn        = DateTime.Now;
                        Customer.CompanyID        = Company.CompanyID;
                        Customer.Address          = "";
                        Customer.ZipCode          = "";
                        Customer.IsEmailVerified  = true;

                        var PhotoPath = "";
                        if (file != null)
                        {
                            PhotoPath = Savefile(file);
                        }

                        Customer.PhotoPath             = PhotoPath;
                        Customer.IsMobileVerified      = false;
                        Customer.ApplicationId         = AdminModel.ApplicationId;
                        Customer.DeviceSerialNo        = AdminModel.DeviceSerialNo;
                        Customer.DeviceType            = AdminModel.DeviceType;
                        Customer.IsUpdated             = false;
                        Customer.IsNotificationSoundOn = true;
                        if (Customer.FirstName == null)
                        {
                            Customer.FirstName = "";
                        }
                        if (Customer.LastName == null)
                        {
                            Customer.LastName = "";
                        }
                        if (Customer.MiddleName == null)
                        {
                            Customer.MiddleName = "";
                        }
                        _CustomerService.InsertCustomer(Customer);

                        var CustomerID = Customer.CustomerId.ToString();
                        AdminModel.CustomerId   = Customer.CustomerId;
                        TempData["ShowMessage"] = "Success";
                        TempData["MessageBody"] = "Admin successfully register.";
                    }
                }
                else
                {
                    if (customerFound.EmailId == AdminModel.EmailID)
                    {
                        TempData["ShowMessage"] = "Error";
                        TempData["MessageBody"] = "Email is already exist.";
                    }
                    else if (customerFound.MobileNo == AdminModel.MobileNo)
                    {
                        TempData["ShowMessage"] = "Error";
                        TempData["MessageBody"] = "MobileNos is already exist.";
                    }
                    else
                    {
                        TempData["ShowMessage"] = "Error";
                        TempData["MessageBody"] = "Some error occured.";
                    }
                }
            }
            else
            {
                var errors           = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);
                TempData["ShowMessage"] = "Error";
                TempData["MessageBody"] = "Please fill the required data.";
                return(View(AdminModel));
            }


            return(RedirectToAction("Index"));
        }
		private void submit_Click(object sender, RoutedEventArgs e)
		{
			if (((customId.Text == string.Empty) || (firstName.Text == string.Empty) || (lastName.Text == string.Empty) ||
				(street.Text == string.Empty) || (city.Text == string.Empty) ||
				(zip.Text == string.Empty) || (email.Text == string.Empty) ||
			  (name.Text == string.Empty) || (country.SelectedValue == null) || !this.marked)
				|| (this.c != "FO" && (this.ico.Text == string.Empty || this.icDph.Text == string.Empty
					|| this.dic.Text == string.Empty || this.name.Text == string.Empty)))
			{
				System.Windows.MessageBox.Show("Musia byť vyplnené poviné údaje");
				return;
			}
			if ((customId.Text.Contains(";")) || (titlePrefix.Text.Contains(";")) ||
						(firstName.Text.Contains(";")) || (lastName.Text.Contains(";")) ||
						(titleSuffix.Text.Contains(";")) || (street.Text.Contains(";")) ||
						(city.Text.Contains(";")) || (zip.Text.Contains(";")) || (email.Text.Contains(";")) ||
					  (name.Text.Contains(";")) || (mobile.Text.Contains(";")) || (ico.Text.Contains(";"))
			 || (dic.Text.Contains(";")) || (icDph.Text.Contains(";")))
			{
				System.Windows.MessageBox.Show("Znak ; je vyhradeni, prosím zmente vstup tak aby neobsahoval znak ; ");
				return;
			}
			Entity.Order order = new Entity.Order();
			order.products = new List<Interface.IOrderItem>();
			Entity.Company company = new Entity.Company();
			company.custom_id = customId.Text.ToString();

			Entity.Person person = new Entity.Person();
			person.titlePrefix = titlePrefix.Text.ToString();
			person.firstName = firstName.Text.ToString();
			person.lastName = lastName.Text.ToString();
			person.titleSuffix = titleSuffix.Text.ToString();

			Entity.Address address = new Entity.Address();
			address.street = street.Text.ToString();
			address.city = city.Text.ToString();
			address.zip = zip.Text.ToString();
			address.country = country.Text.ToString() == "Vyberte krajinu" ? "SVK" : country.Text.ToString();

			Entity.Contact contact = new Entity.Contact();
			contact.email = email.Text.ToString();
			contact.mobile = mobile.Text.ToString();

			company.person = person;
			company.address = address;
			company.contact = contact;

			switch (this.c.ToUpper())
			{
				case "PO":
					{ company.corporatePerson = Interface.CorporatePerson.PO; break; }
				default:
					{ company.corporatePerson = Interface.CorporatePerson.FO; break; }
			}
			if (this.c.ToUpper() != "FO")
			{
				company.name = name.Text.ToString();
				company.ico = ico.Text.ToString();
				company.dic = dic.Text.ToString();
				company.icDph = icDph.Text.ToString();
			}
			else
				company.name = company.person.getFullName();

			//company.id = 1;
			//if (Settings.Config.getCompanies().Count > 0)
			//	company.id = Settings.Config.getCompanies().LastOrDefault(x => x.id > 0).id + 1;

			//order.id = 1;
			//if (Settings.Config.getOrders().Count > 0)
			//	order.id = Settings.Config.getOrders().LastOrDefault(x => x.id > 0).id + 1;

			order.company = company;
			//Settings.Config.getCompanies().Add(company);
			//Settings.Config.getOrders().Add(order);
			Settings.Config.setTempOrder(order);
			onCreatedOrder(new EventArgs());
		}